Module: Jekyll::FridgeFilters
- Defined in:
- lib/jekyll-fridge/fridge_filters.rb
Instance Method Summary collapse
-
#fridge_asset(input) ⇒ Object
Filter for fetching assets Writes static file to asset_dir and returns absolute file path.
- #fridge_choices(input) ⇒ Object
Instance Method Details
#fridge_asset(input) ⇒ Object
Filter for fetching assets Writes static file to asset_dir and returns absolute file path
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jekyll-fridge/fridge_filters.rb', line 5 def fridge_asset(input) return input unless input if input.respond_to?('first') input = input.first['name'] end site = @context.registers[:site] asset_dir = site.config['fridge'].config['asset_dir'] dest_path = File.join(site.dest, asset_dir, input) path = File.join(asset_dir, input) # Check if file already exists if site.keep_files.index(path) != nil return "/#{path}" end asset = site.config['fridge'].client.get("content/upload/#{input}") return input unless asset # play for keeps # this is so jekyll won't clean up the file site.keep_files << path # write file to destination FileUtils.mkdir_p(File.dirname(dest_path)) File.write(dest_path, asset) "/#{path}" end |
#fridge_choices(input) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/jekyll-fridge/fridge_filters.rb', line 33 def fridge_choices(input) arr = input.is_a?(String) ? input.lines : input arr.map do |line| key, value = line.split ":" value = key if value.nil? || !value { "key" => key.strip, "value" => value.strip } end end |