Sha256: feacac71db76753e1fd500843d005c3eb5de0395c12dd22844b356be8a277f53
Contents?: true
Size: 1.49 KB
Versions: 52
Compression:
Stored size: 1.49 KB
Contents
require 'jsduck/util/json' require 'jsduck/util/null_object' require 'jsduck/grouped_asset' module JsDuck # Reads in examples JSON file class Examples < GroupedAsset # Creates Examples object from filename. def self.create(filename, opts) if filename Examples.new(filename, opts) else Util::NullObject.new(:to_array => [], :[] => nil) end end # Parses examples config file def initialize(filename, opts) @groups = Util::Json.read(filename) @opts = opts fix_examples_data build_map_by_name end # Prefix all relative URL-s in examples list with path given in --examples-base-url # # For backwards compatibility: # # - Create names for each example when not present # - Create title from text # - Create description from desc # def fix_examples_data each_item do |ex| ex["name"] = ex["url"] unless ex["name"] unless ex["url"] =~ /^https?:\/\// ex["url"] = @opts.examples_base_url + ex["url"] end unless ex["icon"] =~ /^https?:\/\// ex["icon"] = @opts.examples_base_url + ex["icon"] end unless ex["title"] ex["title"] = ex["text"] ex.delete("text") end unless ex["description"] ex["description"] = ex["desc"] ex.delete("desc") end end end # Extracts example icon URL from example hash def icon_url(example) example["icon"] end end end
Version data entries
52 entries across 52 versions & 3 rubygems