retreive one main cli file
arnaud sellenet
committed Apr 07, 2014
commit 6e9864443f4c78beb5916edd6e6b16cfbb153af9
Showing 3
changed files with
91 additions
and 3 deletions
.rspec
+0
-2
| @@ | @@ -1,2 +0,0 @@ |
| - | --colour |
| - | --backtrace |
locomotive/wagon.rb b/lib/locomotive/wagon.rb
+1
-1
| @@ | @@ -74,7 +74,7 @@ module Locomotive |
| # | |
| def self.generate(name, *args) | |
| Bundler.require 'misc' | |
| - | |
| + | binding.pry |
| lib = "locomotive/wagon/generators/#{name}" | |
| require lib | |
locomotive/wagon/cli/main.rb b/lib/locomotive/wagon/cli/main.rb
+90
-0
| @@ | @@ -1,9 +1,89 @@ |
| require_relative 'helpers/check_path' | |
| require_relative 'helpers/force_color' | |
| + | require_relative 'generate' |
| module Locomotive | |
| module Wagon | |
| module CLI | |
| + | class Generate < Thor |
| + | include Helpers::CheckPath |
| + | |
| + | class_option :path, aliases: '-p', type: :string, default: '.', optional: true, desc: 'if your LocomotiveCMS site is not in the current path' |
| + | |
| + | desc 'content_type SLUG FIELDS', 'Creates a content type with the specified slug and fields.' |
| + | long_desc <<-LONGDESC |
| + | Creates a content type with the specified slug and fields. |
| + | |
| + | SLUG should be plural, lowercase, and underscored. |
| + | |
| + | FIELDS format: field_1[:TYPE][:REQUIRED] field_2[:TYPE][:REQUIRED] ... |
| + | |
| + | TYPE values: string, text, integer, float, boolean, email, date, date_time, file, tags, select, belongs_to, has_many, or many_to_many. Default is string. |
| + | |
| + | To require a field, set REQUIRED to true. The first field is required by default. |
| + | |
| + | Examples: |
| + | |
| + | * wagon generate content_type posts title published_at:date_time:true body:text |
| + | |
| + | * wagon generate content_type products title price:float photo:file category:belongs_to:true |
| + | LONGDESC |
| + | def content_type(name, *fields) |
| + | say('The fields are missing', :red) and return false if fields.empty? |
| + | |
| + | if check_path! |
| + | Locomotive::Wagon.generate :content_type, name, self.options['path'], fields |
| + | end |
| + | end |
| + | |
| + | desc 'page FULLPATH', 'Create a page. No need to pass an extension to the FULLPATH arg' |
| + | long_desc <<-LONGDESC |
| + | Create a page. The generator will ask for the extension (liquid or haml) and also |
| + | if the page is localized or not. |
| + | |
| + | Examples: |
| + | |
| + | * wagon generate page contact |
| + | |
| + | * wagon generate page about_us/me |
| + | LONGDESC |
| + | def page(fullpath) |
| + | if path = check_path! |
| + | locales = self.site_config(path)['locales'] |
| + | Locomotive::Wagon.generate :page, fullpath, self.options['path'], locales |
| + | end |
| + | end |
| + | |
| + | desc 'snippet SLUG', 'Create a snippet' |
| + | long_desc <<-LONGDESC |
| + | Create a snippet. The generator will ask for the extension (liquid or haml) and also |
| + | if the snippet is localized or not. |
| + | |
| + | Example: |
| + | |
| + | * wagon generate snippet footer |
| + | LONGDESC |
| + | def snippet(slug) |
| + | if path = check_path! |
| + | locales = self.site_config(path)['locales'] |
| + | Locomotive::Wagon.generate :snippet, slug, self.options['path'], locales |
| + | end |
| + | end |
| + | |
| + | protected |
| + | |
| + | # Read the YAML config file of a LocomotiveCMS site. |
| + | # The path should be returned by the check_path! method first. |
| + | # |
| + | # @param [ String ] path The full path to a LocomotiveCMS site. |
| + | # |
| + | # @return [ Hash ] The site |
| + | # |
| + | def site_config(path = nil) |
| + | YAML.load_file(File.join(path, 'config', 'site.yml')) |
| + | end |
| + | end |
| + | |
| class Main < Thor | |
| include Helpers::CheckPath | |
| @@ | @@ -17,6 +97,16 @@ module Locomotive |
| say Locomotive::Wagon::VERSION | |
| end | |
| + | desc 'generate RESOURCE ARGUMENTS', 'Generates a content_type, page, or snippet' |
| + | long_desc <<-LONGDESC |
| + | Generates a content_type, page, or snippet |
| + | |
| + | RESOURCE can be set to content_type, page, or snippet. |
| + | |
| + | Use wagon generate help [RESOURCE] for usage information and examples. |
| + | LONGDESC |
| + | subcommand 'generate', Generate |
| + | |
| desc 'init NAME [PATH] [OPTIONS]', 'Create a brand new site' | |
| method_option :template, aliases: '-t', type: 'string', default: 'blank', desc: 'instead of building from a blank site, you can also have a pre-fetched site from a template (see the templates command)' | |
| method_option :lib, aliases: '-l', type: 'string', desc: 'Path to an external ruby lib or generator' | |