preparing Wagon for the desktop app version [wip]
did
committed Jan 13, 2014
commit 84c59a029ae0211c902356da5234d098a67fa1f6
Showing 12
changed files with
112 additions
and 17 deletions
bin/wagon
+2
-0
| @@ | @@ -3,6 +3,8 @@ |
| # needed if you launch it without bundler | |
| $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) | |
| + | $stdout.sync = true |
| + | |
| require 'locomotive/wagon' | |
| require 'locomotive/wagon/cli' | |
locomotive/wagon.rb b/lib/locomotive/wagon.rb
+3
-2
| @@ | @@ -10,9 +10,10 @@ module Locomotive |
| # @param [ String ] name The name of the site (underscored) | |
| # @param [ String ] path The destination path of the site | |
| # @param [ Object ] generator The wrapping class of the generator itself | |
| + | # @param [ String ] options Options for the generator (ex: --force_haml) |
| # | |
| - | def self.init(name, path, generator) |
| - | generator.klass.start [name, path] |
| + | def self.init(name, path, generator, options) |
| + | generator.klass.start [name, path, options] |
| end | |
| # Start the thin server which serves the LocomotiveCMS site from the system. | |
locomotive/wagon/cli.rb b/lib/locomotive/wagon/cli.rb
+23
-4
| @@ | @@ -30,6 +30,17 @@ module Locomotive |
| end | |
| + | module ForceColor |
| + | |
| + | def force_color_if_asked(options) |
| + | if options[:force_color] |
| + | require 'locomotive/wagon/misc/thor' |
| + | self.shell = Thor::Shell::ForceColor.new |
| + | end |
| + | end |
| + | |
| + | end |
| + | |
| class Generate < Thor | |
| include Locomotive::Wagon::CLI::CheckPath | |
| @@ | @@ -109,6 +120,9 @@ module Locomotive |
| class Main < Thor | |
| include Locomotive::Wagon::CLI::CheckPath | |
| + | include Locomotive::Wagon::CLI::ForceColor |
| + | |
| + | class_option :force_color, aliases: '-c', type: :boolean, default: false, desc: 'Whether or not to use ANSI color in the output.' |
| desc 'version', 'Version of the LocomotiveCMS wagon' | |
| def version | |
| @@ | @@ -116,11 +130,12 @@ module Locomotive |
| say Locomotive::Wagon::VERSION | |
| end | |
| - | desc 'init NAME [PATH]', 'Create a brand new LocomotiveCMS site' |
| + | desc 'init NAME [PATH] [OPTIONS]', 'Create a brand new LocomotiveCMS site' |
| method_option :template, aliases: '-t', type: 'string', default: 'blank', desc: 'instead of building from a blank site, you can have a pre-fetched site with form a template (see the templates command)' | |
| method_option :lib, aliases: '-l', type: 'string', desc: 'Path to an external ruby lib or generator' | |
| method_option :verbose, aliases: '-v', type: 'boolean', default: false, desc: 'display the full error stack trace if an error occurs' | |
| - | def init(name, path = '.') |
| + | def init(name, path = '.', generator_options = nil) |
| + | force_color_if_asked(options) |
| require 'locomotive/wagon/generators/site' | |
| require File.expand_path(options[:lib]) if options[:lib] | |
| generator = Locomotive::Wagon::Generators::Site.get(options[:template]) | |
| @@ | @@ -128,7 +143,7 @@ module Locomotive |
| say "Unknown site template '#{options[:template]}'", :red | |
| else | |
| begin | |
| - | if Locomotive::Wagon.init(name, path, generator) |
| + | if Locomotive::Wagon.init(name, path, generator, generator_options) |
| self.print_next_instructions_when_site_created(name, path) | |
| end | |
| rescue GeneratorException => e | |
| @@ | @@ -157,16 +172,20 @@ module Locomotive |
| desc 'list_templates', 'List all the templates to create either a site or a content type' | |
| method_option :lib, aliases: '-l', type: 'string', desc: 'Path to an external ruby lib or generator' | |
| + | method_option :json, aliases: '-j', type: :boolean, default: false, desc: 'Output the list in JSON' |
| def list_templates | |
| + | force_color_if_asked(options) |
| require 'locomotive/wagon/generators/site' | |
| require File.expand_path(options[:lib]) if options[:lib] | |
| if Locomotive::Wagon::Generators::Site.empty? | |
| say 'No templates', :red | |
| - | else |
| + | elsif !options[:json] |
| Locomotive::Wagon::Generators::Site.list.each do |info| | |
| say info.name, :bold, false | |
| say " - #{info.description}" unless info.description.blank? | |
| end | |
| + | else |
| + | say Locomotive::Wagon::Generators::Site.list_to_json |
| end | |
| end | |
locomotive/wagon/generators/site.rb b/lib/locomotive/wagon/generators/site.rb
+46
-0
| @@ | @@ -37,6 +37,14 @@ module Locomotive |
| Locomotive::Wagon::Generators::Site::List.instance._list | |
| end | |
| + | # JSON output of the generators list |
| + | # |
| + | # @return [ String ] The JSON output |
| + | # |
| + | def self.list_to_json |
| + | Locomotive::Wagon::Generators::Site::List.instance.to_json |
| + | end |
| + | |
| # Tell if the list of generators is empty or not . | |
| # | |
| # @return [ Boolean ] True if empty | |
| @@ | @@ -84,6 +92,44 @@ module Locomotive |
| self._list.last | |
| end | |
| + | |
| + | # Return the list of site templates in JSON |
| + | # |
| + | # @return [ String ] JSON output |
| + | # |
| + | 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 |
| + | |
| + | 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 |
| + | |
| end | |
| end | |
locomotive/wagon/generators/site/base.rb b/lib/locomotive/wagon/generators/site/base.rb
+14
-0
| @@ | @@ -29,6 +29,20 @@ module Locomotive |
| File.join(target_path, name) | |
| end | |
| + | def self.may_use_haml |
| + | class_option :haml, type: :boolean, default: nil, required: false, desc: 'HAML over HTML?' |
| + | end |
| + | |
| + | protected |
| + | |
| + | def haml? |
| + | if options[:haml].nil? |
| + | yes?('Do you prefer HAML templates ?') |
| + | else |
| + | options[:haml] |
| + | end |
| + | end |
| + | |
| end | |
| end | |
locomotive/wagon/generators/site/blank.rb b/lib/locomotive/wagon/generators/site/blank.rb
+4
-2
| @@ | @@ -5,8 +5,10 @@ module Locomotive |
| class Blank < Base | |
| + | may_use_haml |
| + | |
| def choose_haml_over_html | |
| - | if yes?('Do you prefer HAML templates ?') |
| + | if haml? |
| remove_file File.join(self.destination, 'app/views/pages/index.liquid') | |
| remove_file File.join(self.destination, 'app/views/pages/404.liquid') | |
| else | |
| @@ | @@ -17,7 +19,7 @@ module Locomotive |
| end | |
| Locomotive::Wagon::Generators::Site.register(:blank, Blank, %{ | |
| - | A blank LocomotiveCMS site with the minimal files. |
| + | A blank site with the minimal files. |
| }) | |
| end | |
| end | |
locomotive/wagon/generators/site/bootstrap2.rb b/lib/locomotive/wagon/generators/site/bootstrap2.rb
+4
-2
| @@ | @@ -5,8 +5,10 @@ module Locomotive |
| class Bootstrap2 < Base | |
| + | may_use_haml |
| + | |
| def choose_haml_over_html | |
| - | if yes?('Do you prefer HAML templates ?') |
| + | if haml? |
| remove_file File.join(self.destination, 'app/views/pages/index.liquid') | |
| remove_file File.join(self.destination, 'app/views/pages/404.liquid') | |
| remove_file File.join(self.destination, 'app/views/snippets/footer.liquid') | |
| @@ | @@ -20,7 +22,7 @@ module Locomotive |
| end | |
| Locomotive::Wagon::Generators::Site.register(:bootstrap2, Bootstrap2, %{ | |
| - | A LocomotiveCMS site with Twitter Bootstrap (v2.3.2) and Font Awesome (v3.2.1). |
| + | A site with Twitter Bootstrap (v2.3.2) and Font Awesome (v3.2.1). |
| }) | |
| end | |
| end | |
locomotive/wagon/generators/site/bootstrap3.rb b/lib/locomotive/wagon/generators/site/bootstrap3.rb
+4
-2
| @@ | @@ -5,8 +5,10 @@ module Locomotive |
| class Bootstrap3 < Base | |
| + | may_use_haml |
| + | |
| def choose_haml_over_html | |
| - | if yes?('Do you prefer HAML templates ?') |
| + | if haml? |
| remove_file File.join(self.destination, 'app/views/pages/index.liquid') | |
| remove_file File.join(self.destination, 'app/views/pages/404.liquid') | |
| remove_file File.join(self.destination, 'app/views/snippets/footer.liquid') | |
| @@ | @@ -20,7 +22,7 @@ module Locomotive |
| end | |
| Locomotive::Wagon::Generators::Site.register(:bootstrap3, Bootstrap3, %{ | |
| - | A LocomotiveCMS site powered by Twitter bootstrap (v3.0.0). |
| + | A site powered by Twitter bootstrap (v3.0.0). |
| }) | |
| end | |
| end | |
locomotive/wagon/generators/site/foundation.rb b/lib/locomotive/wagon/generators/site/foundation.rb
+4
-2
| @@ | @@ -5,8 +5,10 @@ module Locomotive |
| class Foundation < Base | |
| + | may_use_haml |
| + | |
| def choose_haml_over_html | |
| - | if yes?('Do you prefer HAML templates ?') |
| + | if haml? |
| remove_file File.join(self.destination, 'app/views/pages/index.liquid') | |
| remove_file File.join(self.destination, 'app/views/pages/404.liquid') | |
| remove_file File.join(self.destination, 'app/views/snippets/footer.liquid') | |
| @@ | @@ -20,7 +22,7 @@ module Locomotive |
| end | |
| Locomotive::Wagon::Generators::Site.register(:foundation, Foundation, %{ | |
| - | A LocomotiveCMS site powered by Foundation (v4.3.2). |
| + | A site powered by Foundation (v4.3.2). |
| }) | |
| end | |
| end | |
locomotive/wagon/generators/site/unzip.rb b/lib/locomotive/wagon/generators/site/unzip.rb
+6
-2
| @@ | @@ -8,13 +8,17 @@ module Locomotive |
| class Unzip < Base | |
| + | class_option :location, type: :string, default: nil, required: false, desc: 'Location of the zip file' |
| + | |
| + | @@source_root = nil |
| + | |
| def prepare | |
| remove_file join('tmp') | |
| empty_directory join('tmp') | |
| end | |
| def ask_for_location | |
| - | @location = ask('What is the location (on the filesystem or url) of the zip file ?') |
| + | @location = options[:location] || ask('What is the location (on the filesystem or url) of the zip file ?') |
| raise GeneratorException.new('Please enter a location') if @location.blank? | |
| end | |
| @@ | @@ -73,7 +77,7 @@ module Locomotive |
| end | |
| Locomotive::Wagon::Generators::Site.register(:unzip, Unzip, %{ | |
| - | Unzip a local or remote (http, https, ftp) zipped LocomotiveCMS site. |
| + | Unzip a local or remote (http, https, ftp) zipped site. |
| }) | |
| end | |
| end | |
locomotive/wagon/version.rb b/lib/locomotive/wagon/version.rb
+1
-1
| @@ | @@ -1,5 +1,5 @@ |
| module Locomotive | |
| module Wagon | |
| - | VERSION = '1.4.0' |
| + | VERSION = '1.4.1' |
| end | |
| end | |
locomotivecms_wagon.gemspec
+1
-0
| @@ | @@ -29,6 +29,7 @@ Gem::Specification.new do |gem| |
| gem.add_dependency 'sprockets-sass', '~> 1.0.1' | |
| gem.add_dependency 'rack-cache', '~> 1.1' | |
| gem.add_dependency 'better_errors', '~> 1.0.1' | |
| + | gem.add_dependency 'rubyzip', '~> 1.1.0' |
| gem.add_dependency 'listen', '~> 0.7.0' | |