machined 0.9.3 → 1.0.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.
@@ -1,14 +1,17 @@
1
1
  require 'active_support/core_ext/hash/keys'
2
2
  require 'active_support/core_ext/hash/slice'
3
+ require 'shellwords'
3
4
  require 'thor'
4
5
 
5
6
  module Machined
6
7
  class CLI < Thor
7
8
  include Thor::Actions
8
-
9
+
10
+ SAVED_OPTIONS_FILE = '.machined'
11
+
9
12
  default_task :help
10
13
  source_root File.expand_path('../templates', __FILE__)
11
-
14
+
12
15
  class_option 'root', :aliases => '-r',
13
16
  :desc => 'Path to the root directory of the project',
14
17
  :default => '.'
@@ -21,19 +24,19 @@ module Machined
21
24
  class_option 'environment', :aliases => '-e',
22
25
  :desc => 'Sets the environment',
23
26
  :default => 'development'
24
-
27
+
25
28
  desc 'compile', 'Compiles the site from the source files'
26
29
  def compile
27
30
  machined.compile
28
31
  end
29
32
  map %w(c build b) => :compile
30
-
33
+
31
34
  desc 'new SITE_NAME', 'Generates a new site with the give name'
32
35
  def new(site_name)
33
36
  directory 'site', site_name
34
37
  end
35
38
  map %w(n generate g) => :new
36
-
39
+
37
40
  desc 'server', 'Runs a local Rack based web server'
38
41
  method_option :port, :aliases => '-p',
39
42
  :desc => 'Serve at the given port',
@@ -53,25 +56,25 @@ module Machined
53
56
  Rack::Server.start rack_options
54
57
  end
55
58
  map %w(s rackup r) => :server
56
-
59
+
57
60
  desc 'version', 'Prints out the version'
58
61
  def version
59
62
  say VERSION
60
63
  end
61
64
  map %w(v -v --version) => :version
62
-
65
+
63
66
  protected
64
-
67
+
65
68
  def machined
66
69
  @machined ||= Environment.new machined_options
67
70
  end
68
-
71
+
69
72
  # Returns the current environment, using the 'RACK_ENV' variable
70
73
  # if set.
71
74
  def environment # :nodoc
72
75
  ENV['RACK_ENV'] || options['environment']
73
76
  end
74
-
77
+
75
78
  # Returns the options needed for setting up
76
79
  # Machined environment.
77
80
  def machined_options # :nodoc:
@@ -79,21 +82,43 @@ module Machined
79
82
  machined_options[:environment] = environment
80
83
  end
81
84
  end
82
-
85
+
83
86
  # Returns the options needed for setting up the Rack server.
84
87
  def rack_options # :nodoc:
85
88
  symbolized_options(:port, :host, :server, :daemonize, :pid).tap do |rack_options|
86
89
  rack_options[:environment] = environment
87
- rack_options[:Port] = rack_options.delete :port
88
- rack_options[:Host] = rack_options.delete :host
89
- rack_options[:app] = machined
90
+ rack_options[:Port] = rack_options.delete :port
91
+ rack_options[:Host] = rack_options.delete :host
92
+ rack_options[:app] = machined
90
93
  end
91
94
  end
92
-
95
+
93
96
  # Returns a mutable options hash with symbolized keys.
94
97
  # Optionally, returns only the keys given.
95
98
  def symbolized_options(*keys) # :nodoc:
96
- {}.merge(options).symbolize_keys.slice(*keys)
99
+ @symbolized_options ||= begin
100
+ opts = {}.merge(options)
101
+ opts.merge! saved_options if saved_options?
102
+ opts.symbolize_keys
103
+ end
104
+ @symbolized_options.slice(*keys)
105
+ end
106
+
107
+ # Returns the parsed saved options.
108
+ def saved_options
109
+ parse_options File.read(SAVED_OPTIONS_FILE)
110
+ end
111
+
112
+ # Returns true if there's a saved options file in the project
113
+ def saved_options?
114
+ File.exist? SAVED_OPTIONS_FILE
115
+ end
116
+
117
+ # Use Thor::Options to parse the given options String (or Array).
118
+ def parse_options(options)
119
+ options = Shellwords.split(options) unless options.is_a?(Array)
120
+ parser = Thor::Options.new(self.class.class_options)
121
+ parser.parse(options)
97
122
  end
98
123
  end
99
124
  end
@@ -2,7 +2,7 @@ source :rubygems
2
2
 
3
3
  gem 'machined', '<%= Machined::VERSION %>'
4
4
 
5
- gem 'sass', '~> 3.1'
5
+ gem 'sass', '~> 3.2'
6
6
  gem 'coffee-script', '~> 2.2'
7
7
 
8
8
  group :production do
@@ -1,10 +1,10 @@
1
1
  if environment.production?
2
2
  # Compress javascripts and stylesheets
3
3
  config.compress = true
4
-
4
+
5
5
  # Generate digests for assets URLs
6
6
  # config.digest_assets = true
7
-
7
+
8
8
  # Create gzipped versions of javascripts and stylesheets
9
9
  # config.gzip_assets = true
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module Machined
2
- VERSION = '0.9.3'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ['lib']
20
20
 
21
21
  s.add_dependency 'rack', '~> 1.5.0'
22
- s.add_dependency 'sprockets', '~> 2.6.0'
23
- s.add_dependency 'sprockets-helpers', '~> 0.7.1'
22
+ s.add_dependency 'sprockets', '~> 2.9.0'
23
+ s.add_dependency 'sprockets-helpers', '~> 0.8.0'
24
24
  s.add_dependency 'sprockets-sass', '~> 0.9.1'
25
25
  s.add_dependency 'padrino-helpers', '~> 0.10.6'
26
26
  s.add_dependency 'activesupport', '~> 3.2.3'
@@ -7,8 +7,17 @@ describe Machined::CLI do
7
7
  Machined::Environment.should_receive(:new).with(:root => '.', :output_path => 'public', :environment => 'production', :config_path => 'machined.rb').and_return(machined)
8
8
  machined_cli 'compile -e production'
9
9
  end
10
+
11
+ it 'uses saved options' do
12
+ within_construct do |c|
13
+ c.file '.machined', '--root app --output-path site --config-path app.rb'
14
+ machined.should_receive(:compile)
15
+ Machined::Environment.should_receive(:new).with(:root => 'app', :output_path => 'site', :environment => 'production', :config_path => 'app.rb').and_return(machined)
16
+ machined_cli 'compile -e production'
17
+ end
18
+ end
10
19
  end
11
-
20
+
12
21
  describe '#new' do
13
22
  it 'creates a machined site directory' do
14
23
  within_construct do |c|
@@ -16,7 +25,7 @@ describe Machined::CLI do
16
25
  File.directory?('my_site').should be_true
17
26
  end
18
27
  end
19
-
28
+
20
29
  it 'creates source directories' do
21
30
  within_construct do |c|
22
31
  machined_cli 'new my_site'
@@ -27,14 +36,14 @@ describe Machined::CLI do
27
36
  File.directory?('my_site/assets/stylesheets').should be_true
28
37
  end
29
38
  end
30
-
39
+
31
40
  it 'creates an output path' do
32
41
  within_construct do |c|
33
42
  machined_cli 'new my_site'
34
43
  File.directory?('my_site/public').should be_true
35
44
  end
36
45
  end
37
-
46
+
38
47
  it 'creates an default index page' do
39
48
  within_construct do |c|
40
49
  machined_cli 'new my_site'
@@ -47,7 +56,7 @@ describe Machined::CLI do
47
56
  CONTENT
48
57
  end
49
58
  end
50
-
59
+
51
60
  it 'creates a default layout' do
52
61
  within_construct do |c|
53
62
  machined_cli 'new my_site'
@@ -67,39 +76,39 @@ describe Machined::CLI do
67
76
  CONTENT
68
77
  end
69
78
  end
70
-
79
+
71
80
  it 'creates a default javascript file' do
72
81
  within_construct do |c|
73
82
  machined_cli 'new my_site'
74
83
  File.exist?('my_site/assets/javascripts/application.js.coffee').should be_true
75
84
  end
76
85
  end
77
-
86
+
78
87
  it 'creates a default stylesheet file' do
79
88
  within_construct do |c|
80
89
  machined_cli 'new my_site'
81
90
  File.exist?('my_site/assets/stylesheets/application.css.scss').should be_true
82
91
  end
83
92
  end
84
-
93
+
85
94
  it 'creates a default Gemfile' do
86
95
  within_construct do |c|
87
96
  machined_cli 'new my_site'
88
97
  File.read('my_site/Gemfile').should == <<-CONTENT.unindent
89
98
  source :rubygems
90
-
99
+
91
100
  gem 'machined', '#{Machined::VERSION}'
92
-
93
- gem 'sass', '~> 3.1'
101
+
102
+ gem 'sass', '~> 3.2'
94
103
  gem 'coffee-script', '~> 2.2'
95
-
104
+
96
105
  group :production do
97
106
  gem 'uglifier', '~> 1.0'
98
107
  end
99
108
  CONTENT
100
109
  end
101
110
  end
102
-
111
+
103
112
  it 'creates a default config file' do
104
113
  within_construct do |c|
105
114
  machined_cli 'new my_site'
@@ -107,21 +116,21 @@ describe Machined::CLI do
107
116
  if environment.production?
108
117
  # Compress javascripts and stylesheets
109
118
  config.compress = true
110
-
119
+
111
120
  # Generate digests for assets URLs
112
121
  # config.digest_assets = true
113
-
122
+
114
123
  # Create gzipped versions of javascripts and stylesheets
115
124
  # config.gzip_assets = true
116
125
  end
117
-
126
+
118
127
  helpers do
119
128
  # Define helper methods here
120
129
  end
121
130
  CONTENT
122
131
  end
123
132
  end
124
-
133
+
125
134
  it 'creates a default rackup file' do
126
135
  within_construct do |c|
127
136
  machined_cli 'new my_site'
@@ -132,16 +141,26 @@ describe Machined::CLI do
132
141
  end
133
142
  end
134
143
  end
135
-
144
+
136
145
  describe '#server' do
137
- it 'should start a Rack server' do
146
+ it 'starts a Rack server' do
138
147
  app = machined
139
148
  Machined::Environment.should_receive(:new).with(:root => '.', :output_path => 'site', :environment => 'production', :config_path => 'machined.rb').and_return(app)
140
149
  Rack::Server.should_receive(:start).with(hash_including(:app => app, :environment => 'production', :Port => 5000))
141
150
  machined_cli 'server -o site -e production -p 5000'
142
151
  end
152
+
153
+ it 'uses saved options' do
154
+ within_construct do |c|
155
+ c.file '.machined', '--root app --output-path site --config-path app.rb'
156
+ app = machined
157
+ Machined::Environment.should_receive(:new).with(:root => 'app', :output_path => 'site', :config_path => 'app.rb', :environment => 'development').and_return(app)
158
+ Rack::Server.should_receive(:start).with(hash_including(:app => app))
159
+ machined_cli 'server'
160
+ end
161
+ end
143
162
  end
144
-
163
+
145
164
  describe '#version' do
146
165
  it 'prints out the current version number' do
147
166
  output = machined_cli 'version'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: machined
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-06 00:00:00.000000000 Z
12
+ date: 2013-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 2.6.0
37
+ version: 2.9.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 2.6.0
45
+ version: 2.9.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: sprockets-helpers
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 0.7.1
53
+ version: 0.8.0
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 0.7.1
61
+ version: 0.8.0
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: sprockets-sass
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -428,7 +428,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
428
428
  version: '0'
429
429
  segments:
430
430
  - 0
431
- hash: 3230074138858488384
431
+ hash: -3708924351974803974
432
432
  required_rubygems_version: !ruby/object:Gem::Requirement
433
433
  none: false
434
434
  requirements:
@@ -437,7 +437,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
437
437
  version: '0'
438
438
  segments:
439
439
  - 0
440
- hash: 3230074138858488384
440
+ hash: -3708924351974803974
441
441
  requirements: []
442
442
  rubyforge_project: machined
443
443
  rubygems_version: 1.8.23