massimo 0.6.8 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/massimo CHANGED
@@ -1,4 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'massimo'
4
- Massimo::CLI.start
4
+
5
+ case ARGV.shift
6
+ when 'b', 'build'
7
+ Massimo::Commands::Build
8
+ when 'g', 'generate'
9
+ Massimo::Commands::Generate
10
+ when nil, '-h', '--help', 'help'
11
+ Massimo::Commands::Help
12
+ when 's', 'server'
13
+ Massimo::Commands::Server
14
+ when '-v', '--version', 'version'
15
+ Massimo::Commands::Version
16
+ when 'w', 'watch'
17
+ Massimo::Commands::Watch
18
+ else
19
+ Massimo::Commands::Help
20
+ end.run
@@ -0,0 +1,87 @@
1
+ require 'optparse'
2
+ require 'thor/actions'
3
+ require 'thor/shell'
4
+
5
+ module Massimo
6
+ module Commands
7
+ class Base
8
+ include Thor::Actions
9
+ include Thor::Shell
10
+
11
+ attr_reader :options, :parser
12
+
13
+ def self.run
14
+ command = self.new
15
+ command.parse
16
+ command.run
17
+ end
18
+
19
+ def initialize()
20
+ @options = {}
21
+ @parser = OptionParser.new
22
+
23
+ parser.banner = "#{banner}\n" if respond_to?(:banner)
24
+ common_options
25
+ add_options if respond_to?(:add_options)
26
+
27
+ # needed for Thor::Actions to work
28
+ self.destination_root = nil
29
+ end
30
+
31
+ def common_options
32
+ parser.on('-c', '--config FILE', 'Path to the config file') do |config|
33
+ options[:config] = config
34
+ end
35
+
36
+ parser.on('-s', '--source-path PATH', 'Path to the source dir') do |path|
37
+ options[:source_path] = path
38
+ end
39
+
40
+ parser.on('-o', '--output-path PATH', 'Path to the output dir') do |path|
41
+ options[:output_path] = path
42
+ end
43
+
44
+ parser.on('-e', '--environment ENV', 'Sets the Site environment') do |env|
45
+ options[:environment] = env
46
+ end
47
+
48
+ parser.on('-p', '--production', "Sets the Site environment to 'production'") do |production|
49
+ options[:environment] = 'production'
50
+ end
51
+ end
52
+
53
+ def parse
54
+ begin
55
+ parser.parse(ARGV)
56
+ rescue
57
+ say parser
58
+ exit
59
+ end
60
+ end
61
+
62
+ def run
63
+ end
64
+
65
+ def site
66
+ @site ||= begin
67
+ site = Massimo::Site.new config_file(:yml)
68
+ site.config.environment = options[:environment] if options[:environment]
69
+ site.config.source_path = options[:source_path] if options[:source_path]
70
+ site.config.output_path = options[:output_path] if options[:output_path]
71
+ if config_rb = config_file(:rb)
72
+ site.instance_eval File.read(config_rb)
73
+ end
74
+ site
75
+ end
76
+ end
77
+
78
+ def config_file(ext)
79
+ if options[:config] && File.extname(options[:config]) == ".#{ext}"
80
+ options[:config]
81
+ elsif File.exist?("config.#{ext}")
82
+ "config.#{ext}"
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,19 @@
1
+ module Massimo
2
+ module Commands
3
+ class Build < Base
4
+ def banner
5
+ %{
6
+ #{Massimo::UI.color('massimo build', :cyan)}
7
+ Builds the site from the source files.
8
+ }
9
+ end
10
+
11
+ def run
12
+ Massimo::UI.report_errors do
13
+ site.process
14
+ Massimo::UI.say 'massimo has built your site', :growl => true
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,63 @@
1
+ require 'active_support/core_ext/string/starts_ends_with'
2
+ require 'active_support/inflector'
3
+
4
+ module Massimo
5
+ module Commands
6
+ class Generate < Base
7
+ def banner
8
+ %{
9
+ #{Massimo::UI.color('massimo generate SITE_OR_RESOURCE [FILE]', :cyan)}
10
+ Generates a new site:
11
+ massimo generate myblog
12
+ Within a massimo project, you can generate a new resource file:
13
+ massimo generate page contact.haml
14
+ }
15
+ end
16
+
17
+ def add_options
18
+ @site_or_resource = ARGV.shift
19
+
20
+ if ARGV.first && !ARGV.first.starts_with?('-')
21
+ @file = ARGV.shift
22
+ end
23
+
24
+ options.merge!(
25
+ :page_ext => 'haml',
26
+ :javascript_ext => 'js',
27
+ :stylesheet_ext => 'sass'
28
+ )
29
+
30
+ parser.on('--page', '--page-ext EXT', 'The extension used for generated Pages and Views') do |ext|
31
+ options[:page_ext] = ext
32
+ end
33
+
34
+ parser.on('--js', '--javascript-ext EXT', 'The extension used for generated Javascripts') do |ext|
35
+ options[:javascript_ext] = ext
36
+ end
37
+
38
+ parser.on('--css', '--stylesheet-ext EXT', 'The extension used for generated Stylesheets') do |ext|
39
+ options[:stylesheet_ext] = ext
40
+ end
41
+ end
42
+
43
+ def run
44
+ if @file
45
+ create_file File.join(site.config.path_for(@site_or_resource.pluralize), @file)
46
+ else
47
+ empty_directory @site_or_resource
48
+ inside @site_or_resource do
49
+ site.resources.each do |resource|
50
+ empty_directory(resource.path)
51
+ end
52
+ create_file File.join(Massimo::Page.path, "index.#{options[:page_ext]}")
53
+ create_file File.join(Massimo::Javascript.path, "main.#{options[:javascript_ext]}")
54
+ create_file File.join(Massimo::Stylesheet.path, "main.#{options[:stylesheet_ext]}")
55
+ create_file File.join(Massimo::View.path, "layouts/main.#{options[:page_ext]}")
56
+ empty_directory site.config.output_path
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,35 @@
1
+ require 'active_support/core_ext/string/conversions'
2
+
3
+ module Massimo
4
+ module Commands
5
+ class Help < Base
6
+ def add_options
7
+ command_name = ARGV.shift
8
+ unless command_name.nil? or %w( help version ).include?(command_name)
9
+ @command = "Massimo::Commands::#{command_name.camelize}".constantize rescue nil
10
+ end
11
+ end
12
+
13
+ def run
14
+ if @command
15
+ puts @command.new.parser
16
+ else
17
+ puts %{
18
+ #{Massimo::UI.color('massimo', :cyan)}
19
+ a static website builder
20
+
21
+ Commands:
22
+ massimo build # Builds the site
23
+ massimo generate SITE_OR_RESOURCE [FILE] # Generates a new site
24
+ Optionally generates a resource file
25
+ massimo help [COMMAND] # Shows info about a specific command
26
+ massimo server [PORT] # Runs a local web server
27
+ massimo version # Displays current version
28
+ massimo watch # Watches your files for changes
29
+ }
30
+ end
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,24 @@
1
+ require 'active_support/core_ext/string/starts_ends_with'
2
+
3
+ module Massimo
4
+ module Commands
5
+ class Server < Base
6
+ def banner
7
+ %{
8
+ #{Massimo::UI.color('massimo server [PORT]', :cyan)}
9
+ Runs a local Rack based web server on the given port.
10
+ }
11
+ end
12
+
13
+ def add_options
14
+ if ARGV.first && !ARGV.first.starts_with?('-')
15
+ @port = ARGV.shift
16
+ end
17
+ end
18
+
19
+ def run
20
+ Massimo::Server.start(site, (@port || 3000).to_i)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ module Massimo
2
+ module Commands
3
+ class Version < Base
4
+ def run
5
+ puts Massimo::VERSION
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ module Massimo
2
+ module Commands
3
+ class Watch < Base
4
+ def banner
5
+ %{
6
+ #{Massimo::UI.color('massimo watch', :cyan)}
7
+ Watches your files for changes and automatically builds the site.
8
+ }
9
+ end
10
+
11
+ def run
12
+ Massimo::Watcher.start(site)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,4 @@
1
+ require 'active_support/core_ext/string/starts_ends_with'
1
2
  require 'rack'
2
3
 
3
4
  module Massimo
@@ -5,6 +6,11 @@ module Massimo
5
6
  class << self
6
7
  def start(site, port = 3000)
7
8
  Massimo::UI.say "massimo is serving your site at http://localhost:#{port}", :growl => true
9
+ trap('INT') do
10
+ Massimo::UI.say 'massimo is shutting down your server', :growl => true
11
+ Rack::Handler::WEBrick.shutdown
12
+ end
13
+
8
14
  app = Rack::Builder.new do
9
15
  use Rack::ShowExceptions
10
16
  run Massimo::Server.new(site)
@@ -21,7 +27,7 @@ module Massimo
21
27
 
22
28
  def call(env)
23
29
  @watcher.process
24
- env['PATH_INFO'] << 'index.html' if env['PATH_INFO'] =~ /\/$/
30
+ env['PATH_INFO'] << 'index.html' if env['PATH_INFO'].ends_with? '/'
25
31
  @file_server.call(env)
26
32
  end
27
33
  end
data/lib/massimo.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Massimo
2
- autoload :CLI, 'massimo/cli'
3
2
  autoload :Config, 'massimo/config'
4
3
  autoload :Helpers, 'massimo/helpers'
5
4
  autoload :Javascript, 'massimo/javascript'
@@ -12,7 +11,17 @@ module Massimo
12
11
  autoload :View, 'massimo/view'
13
12
  autoload :Watcher, 'massimo/watcher'
14
13
 
15
- VERSION = '0.6.8'
14
+ module Commands
15
+ autoload :Base, 'massimo/commands/base'
16
+ autoload :Build, 'massimo/commands/build'
17
+ autoload :Generate, 'massimo/commands/generate'
18
+ autoload :Help, 'massimo/commands/help'
19
+ autoload :Server, 'massimo/commands/server'
20
+ autoload :Version, 'massimo/commands/version'
21
+ autoload :Watch, 'massimo/commands/watch'
22
+ end
23
+
24
+ VERSION = '0.7.0'
16
25
 
17
26
  class << self
18
27
  def site
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: massimo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
9
- - 8
10
- version: 0.6.8
8
+ - 7
9
+ - 0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pete Browne
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-02 00:00:00 -05:00
18
+ date: 2010-07-06 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -321,8 +321,14 @@ files:
321
321
  - lib/massimo/server.rb
322
322
  - lib/massimo/view.rb
323
323
  - lib/massimo/page.rb
324
+ - lib/massimo/commands/build.rb
325
+ - lib/massimo/commands/server.rb
326
+ - lib/massimo/commands/generate.rb
327
+ - lib/massimo/commands/help.rb
328
+ - lib/massimo/commands/watch.rb
329
+ - lib/massimo/commands/version.rb
330
+ - lib/massimo/commands/base.rb
324
331
  - lib/massimo/resource.rb
325
- - lib/massimo/cli.rb
326
332
  - lib/massimo/config.rb
327
333
  - lib/massimo/ui.rb
328
334
  - lib/massimo/watcher.rb
data/lib/massimo/cli.rb DELETED
@@ -1,99 +0,0 @@
1
- require 'thor'
2
-
3
- module Massimo
4
- class CLI < Thor
5
- include Thor::Actions
6
-
7
- default_task :build
8
- class_option 'config', :desc => 'Path to the config file', :aliases => '-c'
9
- class_option 'source_path', :desc => 'Path to the source dir', :aliases => '-s'
10
- class_option 'output_path', :desc => 'Path to the output dir', :aliases => '-o'
11
- class_option 'environment', :desc => 'Sets the Site environment', :aliases => '-e'
12
- class_option 'production', :desc => "Sets the Site environment to 'production'", :aliases => '-p', :type => :boolean
13
-
14
- desc 'build', 'Builds the site'
15
- def build
16
- Massimo::UI.report_errors do
17
- site.process
18
- Massimo::UI.say 'massimo has built your site', :growl => true
19
- end
20
- end
21
- map 'b' => :build
22
-
23
- desc 'watch', 'Watches your files for changes and rebuilds'
24
- def watch
25
- Massimo::Watcher.start(site)
26
- end
27
- map 'w' => :watch
28
-
29
- desc 'server [PORT]', 'Runs a local web server and processes the site on save'
30
- def server(port = 3000)
31
- Massimo::Server.start(site, port.to_i)
32
- end
33
- map 's' => :server
34
-
35
- desc 'generate SITE_OR_RESOURCE [FILE]', 'Generates a new site. Optionally generates a resource file.'
36
- method_option 'page_ext',
37
- :desc => 'The extension used for generated Pages and Views',
38
- :default => 'haml',
39
- :aliases => '--page'
40
- method_option 'javascript_ext',
41
- :desc => 'The extension used for generated Javascripts',
42
- :default => 'js',
43
- :aliases => '--js'
44
- method_option 'stylesheet_ext',
45
- :desc => 'The extension used for generated Stylesheets',
46
- :default => 'sass',
47
- :aliases => '--css'
48
- def generate(site_or_resource, file = nil)
49
- require 'active_support/inflector'
50
-
51
- if file
52
- create_file File.join(site.config.path_for(site_or_resource.pluralize), file)
53
- else
54
- empty_directory site_or_resource
55
- inside site_or_resource do
56
- site.resources.each do |resource|
57
- empty_directory(resource.path)
58
- end
59
- create_file File.join(Massimo::Page.path, "index.#{options[:page_ext]}")
60
- create_file File.join(Massimo::Javascript.path, "main.#{options[:javascript_ext]}")
61
- create_file File.join(Massimo::Stylesheet.path, "main.#{options[:stylesheet_ext]}")
62
- create_file File.join(Massimo::View.path, "layouts/main.#{options[:page_ext]}")
63
- empty_directory site.config.output_path
64
- end
65
- end
66
- end
67
- map 'g' => :generate
68
-
69
- desc 'version', 'Displays current version'
70
- def version
71
- Massimo::UI.say Massimo::VERSION
72
- end
73
- map %w( -v --version ) => :version
74
-
75
- protected
76
-
77
- def site
78
- @site ||= begin
79
- site = Massimo::Site.new config_file(:yml)
80
- site.config.environment = 'production' if options[:production]
81
- site.config.environment = options[:environment] if options[:environment]
82
- site.config.source_path = options[:source_path] if options[:source_path]
83
- site.config.output_path = options[:output_path] if options[:output_path]
84
- if config_rb = config_file(:rb)
85
- site.instance_eval File.read(config_rb)
86
- end
87
- site
88
- end
89
- end
90
-
91
- def config_file(ext)
92
- if options[:config] && File.extname(options[:config]) == ".#{ext}"
93
- options[:config]
94
- elsif File.exist?("config.#{ext}")
95
- "config.#{ext}"
96
- end
97
- end
98
- end
99
- end