module SnippetGenerator
Some Definitions for the sake of readability.
Constants
- NEW_LINE
- QUOTE
Public Instance Methods
heading_snippet_export(file_to_write,heading)
click to toggle source
New a YAML Comment to separate sections of snippet file.
# File lib/snippet_generator.rb, line 29 def heading_snippet_export(file_to_write,heading) File.open(file_to_write,"a") { |file| file.write("# "+ heading+NEW_LINE) } 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(file_to_write, form_trigger,form_statement)
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 36 def input_form_snippet_export(file_to_write, form_trigger,form_statement) 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)} if (form_statement.instance_of?(String)) then File.open(file_to_write,"a") { |file| file.write(' '+form_statement)} else form_statement.each do |item| File.open(file_to_write,"a") { |file| file.write(' '+item) } end end File.open(file_to_write,"a") { |file| file.write(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 news picklists based on form fields and values for each field provided
# File lib/snippet_generator.rb, line 53 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(NEW_LINE+' - trigger: '+'":'+trigger+QUOTE+NEW_LINE) } File.open(file_to_write,"a") { |file| file.write(' replace: |-'+NEW_LINE) } if (replacement.instance_of?(String)) then File.open(file_to_write,"a") { |file| file.write(' '+replacement) } else replacement.each do |item| File.open(file_to_write,"a") { |file| file.write(' '+item) } end end File.open(file_to_write,"a") { |file| file.write(NEW_LINE) } end
textarea_snippet_export(file_to_write)
click to toggle source
News a snippet with large text box
# File lib/snippet_generator.rb, line 74 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