refactoring done for the generators
did
committed Jan 14, 2013
commit eee20d71225c577f2a9235c03a87a1f696e0723a
Showing 8
changed files with
23 additions
and 160 deletions
TODO
+2
-2
| @@ | @@ -41,9 +41,9 @@ x content types / liquid |
| - tests | |
| - refactoring: | |
| + | x generators/sites -> generators/site |
| + | x list is only for site generators |
| - move the call to the CC generator directly in the builder.rb file | |
| - | - generators/sites -> generators/site |
| - | - list is only for site generators |
| *** FEATURES *** | |
generators/content_type/app/content_types/%name%.yml.tt
+2
-2
| @@ | @@ -21,11 +21,11 @@ order_by: manually # TODO: list all different values |
| # public_submission_accounts: ['john@acme.net'] | |
| # TODO: explain | |
| - | fields: <% config[:fields].each do |field| %> |
| + | fields: <% config[:fields].each_with_index do |field, index| %> |
| - <%= field.name -%>: # Name of the field | |
| label: <%= field.name.humanize %> | |
| type: <%= field.type %> | |
| - | required: <%= field.required %> |
| + | required: <%= index == 0 ? true : field.required %> |
| hint: A description of the field for the editors | |
| localized: false<% if field.type == 'select' -%> | |
| # TODO: explain (localization) | |
locomotive/builder.rb b/lib/locomotive/builder.rb
+15
-2
| @@ | @@ -19,8 +19,8 @@ module Locomotive |
| # @param [ Hash ] options The options for the thin server (host, port) | |
| # | |
| def self.serve(path, options) | |
| - | require "thin" |
| - | require "locomotive/builder/server" |
| + | require 'thin' |
| + | require 'locomotive/builder/server' |
| reader = Locomotive::Mounter::Reader::FileSystem.instance | |
| reader.run!(path: path) | |
| @@ | @@ -29,6 +29,19 @@ module Locomotive |
| server.start | |
| end | |
| + | # Generate components for the LocomotiveCMS site such as content types, snippets, pages. |
| + | # |
| + | # @param [ Symbol ] name The name of the generator |
| + | # @param [ Array ] *args The arguments for the generator |
| + | # |
| + | def self.generate(name, *args) |
| + | lib = "locomotive/builder/generators/#{name}" |
| + | require lib |
| + | |
| + | generator = lib.camelize.constantize.new(args, {}, {}) |
| + | generator.invoke_all |
| + | end |
| + | |
| # TODO | |
| def self.pull(path, site_url, email, password) | |
| require 'locomotive/mounter' | |
locomotive/builder/cli.rb b/lib/locomotive/builder/cli.rb
+1
-5
| @@ | @@ -26,11 +26,7 @@ module Locomotive |
| say('The fields are missing', :red) and return false if fields.empty? | |
| if path = check_path! | |
| - | require 'locomotive/builder/generators/content_type' |
| - | |
| - | # TODO: move it to the generate method of the builder.rb file |
| - | script = Locomotive::Builder::Generators::ContentType.new([name, self.options['path'], fields], {}, {}) |
| - | script.invoke_all |
| + | Locomotive::Builder.generate :content_type, name, self.options['path'], fields |
| else | |
| say 'The path does not point to a LocomotiveCMS site', :red | |
| end | |
locomotive/builder/generators.rb b/lib/locomotive/builder/generators.rb
+0
-61
| @@ | @@ -1,61 +0,0 @@ |
| - | # require 'locomotive/builder/generators/list' |
| - | |
| - | # module Locomotive |
| - | # module Builder |
| - | |
| - | # module Generators |
| - | |
| - | # # Register a generator by adding it to the list of existing generators. |
| - | # # |
| - | # # @param [ Symbol ] type The type of the generator (:site, :content_type) |
| - | # # @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. |
| - | # # |
| - | # def self.register(type, name, klass, description = nil) |
| - | # Locomotive::Builder::Generators::List.instance.register(type, name, klass, description) |
| - | # end |
| - | |
| - | # # 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 |
| - | # # |
| - | # def self.get(name) |
| - | # Locomotive::Builder::Generators::List.instance.get(name) |
| - | # end |
| - | |
| - | # # Filter the generators by their type which are for now: |
| - | # # :site and :content_type. If the parameter is nil, |
| - | # # then all the generators are returned |
| - | # # |
| - | # # @param [ Symbol ] type The type of the generators or nil. |
| - | # # |
| - | # # @return [ Array ] The filtered (or not) list of generators |
| - | # # |
| - | # def self.list(type = nil) |
| - | # Locomotive::Builder::Generators::List.instance.filter_by(type) |
| - | # end |
| - | |
| - | # # Tell if the list of generators is empty or not for |
| - | # # a certain kind of generators (or all if the parameter is nil). |
| - | # # |
| - | # # @param [ Symbol ] type The type of the generators or nil |
| - | # # |
| - | # # @return [ Boolean ] True if empty |
| - | # # |
| - | # def self.empty?(type = nil) |
| - | # Locomotive::Builder::Generators::List.instance.empty?(type) |
| - | # end |
| - | |
| - | # end |
| - | |
| - | # end |
| - | # end |
| - | |
| - | # call default generators |
| - | # require 'locomotive/builder/generators/base' |
| - | # require 'locomotive/builder/generators/defaults' |
locomotive/builder/generators/content_type.rb b/lib/locomotive/builder/generators/content_type.rb
+3
-3
| @@ | @@ -32,9 +32,9 @@ module Locomotive |
| name, type, required = raw_attributes.split(':') | |
| OpenStruct.new({ | |
| - | name: name, |
| - | type: type || 'string', |
| - | required: required || false |
| + | name: name, |
| + | type: type || 'string', |
| + | required: %w(true required).include?(required) |
| }) | |
| end | |
| end | |
locomotive/builder/generators/defaults.rb b/lib/locomotive/builder/generators/defaults.rb
+0
-6
| @@ | @@ -1,6 +0,0 @@ |
| - | # # sites |
| - | # require 'locomotive/builder/generators/site/base' |
| - | # require 'locomotive/builder/generators/site/blank' |
| - | # require 'locomotive/builder/generators/site/bootstrap' |
| - | |
| - | # require 'locomotive/builder/generators/content_type' |
| \ No newline at end of file | |
locomotive/builder/generators/list.rb b/lib/locomotive/builder/generators/list.rb
+0
-79
| @@ | @@ -1,79 +0,0 @@ |
| - | # require 'ostruct' |
| - | # require 'singleton' |
| - | |
| - | # module Locomotive |
| - | # module Builder |
| - | # module Generators |
| - | # class List |
| - | |
| - | # include ::Singleton |
| - | |
| - | # attr_accessor :_list |
| - | |
| - | # def initialize |
| - | # self._list = [] |
| - | # end |
| - | |
| - | # # Filter the generators by their type which are for now: |
| - | # # :site and :content_type. If the parameter is nil, |
| - | # # then all the generators are returned |
| - | # # |
| - | # # @param [ Symbol ] type The type of the generators or nil. |
| - | # # |
| - | # # @return [ Array ] The filtered (or not) list of generators |
| - | # # |
| - | # def filter_by(type = nil) |
| - | # if type.nil? |
| - | # self._list |
| - | # else |
| - | # self._list.find_all { |entry| entry.type == type.to_sym } |
| - | # end |
| - | # end |
| - | |
| - | # # Tell if the list of generators is empty or not for |
| - | # # a certain kind of generators (or all if the parameter is nil). |
| - | # # |
| - | # # @param [ Symbol ] type The type of the generators or nil |
| - | # # |
| - | # # @return [ Boolean ] True if empty |
| - | # # |
| - | # def empty?(type = nil) |
| - | # self.filter_by(type).empty? |
| - | # end |
| - | |
| - | # # 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 |
| - | # # |
| - | # def get(name) |
| - | # self._list.detect { |entry| entry.name == name.to_sym } |
| - | # end |
| - | |
| - | # # Register a generator by adding it to the list of existing generators. |
| - | # # |
| - | # # @param [ Symbol ] type The type of the generator (:site, :content_type) |
| - | # # @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. |
| - | # # |
| - | # def register(type, name, klass, description = nil) |
| - | # return false unless self.get(name).nil? |
| - | |
| - | # self._list << OpenStruct.new({ |
| - | # type: type.to_sym, |
| - | # name: name.to_sym, |
| - | # klass: klass, |
| - | # description: description ? description.strip.gsub("\n", '') : nil |
| - | # }) |
| - | |
| - | # self._list.last |
| - | # end |
| - | |
| - | # end |
| - | # end |
| - | # end |
| - | # end |
| \ No newline at end of file | |