module AdHocTemplate::EntryFormatGenerator
Constants
- DEFAULT_ENCODING
Public Class Methods
extract_form(parsed_template, target_format=nil, memo=nil)
click to toggle source
# File lib/ad_hoc_template/entry_format_generator.rb, line 39 def self.extract_form(parsed_template, target_format=nil, memo=nil) labels = extract_form_as_ruby_objects(parsed_template, memo) labels = pull_up_inner_iterations(labels) RecordReader.dump(labels, target_format) end
extract_iteration_labels(parsed_template, memo=nil)
click to toggle source
# File lib/ad_hoc_template/entry_format_generator.rb, line 74 def self.extract_iteration_labels(parsed_template, memo=nil) labels = extract_form_as_ruby_objects(parsed_template, memo) pull_up_inner_iterations(labels).keys end
extract_recipe(template_source, template_path, tag_type=:default, encoding='UTF-8')
click to toggle source
# File lib/ad_hoc_template/entry_format_generator.rb, line 63 def self.extract_recipe(template_source, template_path, tag_type=:default, encoding='UTF-8') recipe = recipe_entry(template_path, tag_type, encoding) parsed_template = Parser.parse(template_source, tag_type) extract_iteration_labels(parsed_template).each do |label| recipe['blocks'].push recipe_block_entry(label) if label.start_with? '#' end RecordReader.dump(recipe, :yaml) end
extract_recipes_from_template_files(template_paths, tag_type=:default, encoding=DEFAULT_ENCODING)
click to toggle source
# File lib/ad_hoc_template/entry_format_generator.rb, line 46 def self.extract_recipes_from_template_files(template_paths, tag_type=:default, encoding=DEFAULT_ENCODING) recipes = map_read_files(template_paths, encoding) do |path, src| extract_recipe(src, path, tag_type, encoding) end recipes.join end
Private Class Methods
each_iteration_label(labels) { |label| ... }
click to toggle source
# File lib/ad_hoc_template/entry_format_generator.rb, line 97 def self.each_iteration_label(labels) labels.keys.each do |label| yield label if labels[label].kind_of? Array end end
extract_form_as_ruby_objects(parsed_template, memo)
click to toggle source
# File lib/ad_hoc_template/entry_format_generator.rb, line 79 def self.extract_form_as_ruby_objects(parsed_template, memo) label_checker = LabelChecker.new parsed_template.accept(label_checker, memo) label_checker.labels end
map_read_files(paths, encoding=DEFAULT_ENCODING) { |path, open(full_path, "rb:BOM|#{encoding}", &:read)| ... }
click to toggle source
# File lib/ad_hoc_template/entry_format_generator.rb, line 56 def self.map_read_files(paths, encoding=DEFAULT_ENCODING) paths.map do |path| full_path = File.expand_path(path) yield path, File.open(full_path, "rb:BOM|#{encoding}", &:read) end end
pull_up_inner_iterations(labels)
click to toggle source
# File lib/ad_hoc_template/entry_format_generator.rb, line 85 def self.pull_up_inner_iterations(labels) each_iteration_label(labels) do |label| labels[label].each do |record| each_iteration_label(record) do |key| inner_label = [label, key.sub(/\A#/, '')].join('|') labels[inner_label] = record.delete(key) end end end labels end
recipe_block_entry(label)
click to toggle source
# File lib/ad_hoc_template/entry_format_generator.rb, line 116 def self.recipe_block_entry(label) { 'label' => label, 'data' => nil, 'data_format' => nil, 'data_encoding' => nil, } end
recipe_entry(template_path, tag_type, encoding)
click to toggle source
# File lib/ad_hoc_template/entry_format_generator.rb, line 103 def self.recipe_entry(template_path, tag_type, encoding) { 'template' => template_path, 'tag_type' => tag_type, 'template_encoding' => encoding, 'data' => nil, 'data_format' => nil, 'data_encoding' => nil, 'output_file' => nil, 'blocks' => [], } end