Class: Jekyll::Converters::CooklangConverter

Inherits:
Converter
  • Object
show all
Defined in:
lib/jekyll/converters/cooklang.rb

Instance Method Summary collapse

Instance Method Details

#convert(content) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/jekyll/converters/cooklang.rb', line 117

def convert(content)
  recipe = CooklangRb::Recipe.from(content)

  ingredients = recipe["steps"].flatten.select { |item|
    item["type"] == "ingredient"
  }.map { |item|
    Ingredient.new(item["quantity"], item["units"], item["name"])
  }

  cookware = recipe["steps"].flatten.select { |item|
    item["type"] == "cookware"
  }.map { |item|
    CookWare.new(item["quantity"], item["name"])
  }

  steps = recipe["steps"].map do |step|
    Step.new(step)
  end

  ingredients_list = UnorderedList.new(ingredients)
  cookware_list = UnorderedList.new(cookware)
  steps_list = OrderedList.new(steps)

  HtmlBeautifier.beautify(
    "<h2>Ingredients</h2>" +
      ingredients_list.to_html +
      "<h2>Cookware</h2>" +
      cookware_list.to_html +
      "<h2>Steps</h2>" +
      steps_list.to_html
  ) + "\n"
end

#matches(ext) ⇒ Object



109
110
111
# File 'lib/jekyll/converters/cooklang.rb', line 109

def matches(ext)
  ext =~ /^.cook/i
end

#output_ext(ext) ⇒ Object



113
114
115
# File 'lib/jekyll/converters/cooklang.rb', line 113

def output_ext(ext)
  ".html"
end