class Locomotive::Wagon::Generators::Site::List
Attributes
_list[RW]
Public Class Methods
new()
click to toggle source
# File lib/locomotive/wagon/generators/site.rb, line 62 def initialize self._list = [] end
Public Instance Methods
get(name)
click to toggle source
Return the information about a generator from its name.
@param [ String ] name The name of the generator
@return [ Object ] The information of the found generator or nil
# File lib/locomotive/wagon/generators/site.rb, line 72 def get(name) self._list.detect { |entry| entry.name == name.to_sym } end
register(name, klass, description = nil)
click to toggle source
Register a generator by adding it to the list of existing generators.
@param [ String ] name The name of the generator @param [ Class ] klass The class of the generator @param [ String ] description The description of the generator (can be nil)
@return [ Boolean ] True if the registration has been successful, false otherwise.
# File lib/locomotive/wagon/generators/site.rb, line 84 def register(name, klass, description = nil) return false unless self.get(name).nil? self._list << OpenStruct.new({ name: name.to_sym, klass: klass, description: description ? description.strip.gsub("\n", '') : nil }) self._list.last end
to_json()
click to toggle source
Return the list of site templates in JSON
@return [ String ] JSON output
# File lib/locomotive/wagon/generators/site.rb, line 100 def to_json self._list.map do |template| # puts template.klass.class_options.inspect # puts class_options_to_json path = template.klass.source_root ? File.expand_path(template.klass.source_root) : nil icon = path ? File.join(path, 'icon.png') : nil { name: template.name, description: template.description, path: path, icon: icon && File.exists?(icon) ? icon : nil, options: class_options_to_json(template) } end.to_json end
Protected Instance Methods
class_options_to_json(template)
click to toggle source
# File lib/locomotive/wagon/generators/site.rb, line 119 def class_options_to_json(template) [].tap do |list| template.klass.class_options.each do |name, option| list << { name: name, label: option.description, type: option.type } end end end