Module: AdHocTemplate::EntryFormatGenerator

Defined in:
lib/ad_hoc_template/entry_format_generator.rb

Defined Under Namespace

Classes: LabelChecker

Constant Summary collapse

DEFAULT_ENCODING =
Encoding.default_external.names[0]

Class Method Summary collapse

Class Method Details

.extract_form(parsed_template, target_format = nil, memo = nil) ⇒ Object



39
40
41
42
43
44
# 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) ⇒ Object



74
75
76
77
# 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') ⇒ Object



63
64
65
66
67
68
69
70
71
72
# 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) ⇒ Object



46
47
48
49
50
51
52
53
54
# 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