class Object
Constants
- NEW_LINE
Some Definitions for the sake of readability.
- QUOTE
Public Instance Methods
heading_snippet_export(file_to_write)
click to toggle source
Create a YAML Comment to separate sections of snippet file.
# File lib/snippet_generator.rb, line 21 def heading_snippet_export(file_to_write) name = "THIS IS AN AWESOME SECTION" File.open(file_to_write,"a") { |file| file.write("#"+ name) } end
initialize_espanso_yml(file_to_write)
click to toggle source
Just writes matches: at the beginning of file so espanso can read the mapping.
# File lib/snippet_generator.rb, line 8 def initialize_espanso_yml(file_to_write) File.open(file_to_write,"a") { |file| file.write('matches:'+NEW_LINE) } end
input_form_snippet_export(form_trigger,form_statement,file_to_write)
click to toggle source
Any input fields should be entered with double brackets around them when passed in as form_statement For example “AJ likes coding in {{language}} and using {{editor}} to write code.”
# File lib/snippet_generator.rb, line 29 def input_form_snippet_export(form_trigger,form_statement,file_to_write) File.open(file_to_write,"a") { |file| file.write(' - trigger: '+QUOTE+':'+form_trigger+QUOTE+NEW_LINE) } File.open(file_to_write,"a") { |file| file.write(' form: |'+NEW_LINE)} File.open(file_to_write,"a") { |file| file.write(' '+form_statement+NEW_LINE)} end
picklist_snippet_export(form_trigger,statement,form_fields,formvalues,file_to_write)
click to toggle source
! TO DO: REFACTOR FORM METHODS INTO ONE METHOD which accounts for all cases. Add comments clarifying ! DATA STRUCTURE NEEDED.
Takes a string for trigger. form_values should be an array.form_fields should also be of type array. Parses statements and creates picklists based on form fields and values for each field provided
# File lib/snippet_generator.rb, line 39 def picklist_snippet_export(form_trigger,statement,form_fields,formvalues,file_to_write) form_fields.each do |value| value+':' end form_type = 'choice' File.open(file_to_write,"a") { |file| file.write(' - trigger: '+'":'+form_trigger+QUOTE+NEW_LINE) } File.open(file_to_write,"a") { |file| file.write(' form: '+QUOTE+statement+QUOTE+NEW_LINE) } form_fields.each do |value| File.open(file_to_write,"a") { |file| file.write(' form_fields:'+NEW_LINE) } File.open(file_to_write,"a") { |file| file.write(' '+form_fields+NEW_LINE) } File.open(file_to_write,"a") { |file| file.write(' type: '+ form_type+NEW_LINE) } File.open(file_to_write,"a") { |file| file.write(' values:'+NEW_LINE) } formvalues.each do |value| File.open(file_to_write,"a") { |file| file.write(' - '+QUOTE+value+QUOTE+NEW_LINE) } end end end
single_snippet_export(file_to_write,trigger,replacement)
click to toggle source
Writes a snippet to file when given trigger and replacement strings.
# File lib/snippet_generator.rb, line 14 def single_snippet_export(file_to_write,trigger,replacement) File.open(file_to_write,"a") { |file| file.write(' - trigger: '+'":'+trigger+QUOTE+NEW_LINE) } File.open(file_to_write,"a") { |file| file.write(' replace: '+QUOTE+replacement+QUOTE+NEW_LINE) } end
textarea_snippet_export(file_to_write)
click to toggle source
Creates a snippet with large text box
# File lib/snippet_generator.rb, line 60 def textarea_snippet_export(file_to_write) File.open(file_to_write,"a") { |file| file.write(' - trigger: '+QUOTE+':'+form_trigger+QUOTE+NEW_LINE) } File.open(file_to_write,"a") { |file| file.write(' form: |'+NEW_LINE)} File.open(file_to_write,"a") { |file| file.write(' '+form_statement+NEW_LINE)} File.open(file_to_write,"a") { |file| file.write(' '+field_names+NEW_LINE) } File.open(file_to_write,"a") { |file| file.write(' '+"multiline: true"+NEW_LINE) } end