Class: Locomotive::Wagon::Generators::Site::List
- Inherits:
-
Object
- Object
- Locomotive::Wagon::Generators::Site::List
- Includes:
- Singleton
- Defined in:
- lib/locomotive/wagon/generators/site.rb
Instance Attribute Summary collapse
-
#_list ⇒ Object
Returns the value of attribute _list.
Instance Method Summary collapse
-
#get(name) ⇒ Object
Return the information about a generator from its name.
-
#initialize ⇒ List
constructor
A new instance of List.
-
#register(name, klass, description = nil) ⇒ Boolean
Register a generator by adding it to the list of existing generators.
-
#to_json ⇒ String
Return the list of site templates in JSON.
Constructor Details
#initialize ⇒ List
Returns a new instance of List.
62 63 64 |
# File 'lib/locomotive/wagon/generators/site.rb', line 62 def initialize self._list = [] end |
Instance Attribute Details
#_list ⇒ Object
Returns the value of attribute _list.
60 61 62 |
# File 'lib/locomotive/wagon/generators/site.rb', line 60 def _list @_list end |
Instance Method Details
#get(name) ⇒ Object
Return the information about a generator from its name.
72 73 74 |
# 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) ⇒ Boolean
Register a generator by adding it to the list of existing generators.
84 85 86 87 88 89 90 91 92 93 94 |
# 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 ⇒ String
Return the list of site templates in JSON
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# 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.(template.klass.source_root) : nil icon = path ? File.join(path, 'icon.png') : nil { name: template.name, description: template.description, path: path, icon: icon && File.exist?(icon) ? icon : nil, options: (template) } end.to_json end |