zassets 0.2.3 → 0.2.4

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/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  z'assets - standalone asset pipeline
2
2
  ====================================
3
3
 
4
- z'assets is a tool based on [Sprockets][] for serving and compiling
4
+ z'assets is a tool based on [Sprockets][] for serving and building
5
5
  web assets. When serving over HTTP (intended for a development
6
- environment), compilation through various preprocessors will happen on
6
+ environment), transpilation through various preprocessors will happen on
7
7
  the fly. For production environment all specified assets are built as
8
8
  files in a directory tree similar to their sources, except filenames
9
9
  will include a hash to help caching.
@@ -33,8 +33,8 @@ directory:
33
33
  - 'assets/styles'
34
34
  - 'assets/scripts'
35
35
  public_path: 'public'
36
- compile_path: 'public/assets'
37
- compile:
36
+ build_path: 'public/assets'
37
+ build:
38
38
  - 'main.css'
39
39
 
40
40
  Then you can launch development HTTP server with the following
@@ -44,7 +44,7 @@ command:
44
44
 
45
45
  And build your assets:
46
46
 
47
- zassets compile
47
+ zassets build
48
48
 
49
49
  You can override some config options using command line arguments,
50
50
  the complete list is printed on the standard output on
@@ -5,7 +5,7 @@ Feature: Builder
5
5
  """
6
6
  paths:
7
7
  - app
8
- compile:
8
+ build:
9
9
  - app.js
10
10
  """
11
11
  And a file named "app/app.js" with "some_content"
@@ -5,7 +5,7 @@ Feature: Manifest
5
5
  """
6
6
  paths:
7
7
  - app
8
- compile:
8
+ build:
9
9
  - app.js
10
10
  """
11
11
  And an empty file named "app/app.js"
@@ -0,0 +1,5 @@
1
+ Feature: Default action (build)
2
+
3
+ Scenario: uses build as the default action when none is provided
4
+ When I successfully run `zassets`
5
+ Then it should build
@@ -4,5 +4,5 @@ Feature: CLI usage
4
4
  When I successfully run `zassets -h`
5
5
  Then the output must contain:
6
6
  """
7
- Usage: zassets [options] compile|serve
7
+ Usage: zassets [options] [build|serve]
8
8
  """
@@ -5,6 +5,6 @@ Feature: Config file loading
5
5
  """
6
6
  &* invalid yaml
7
7
  """
8
- When I run `zassets compile`
8
+ When I run `zassets build`
9
9
  Then it must fail to parse the config
10
10
  And the output must contain "config/zassets.yaml"
@@ -5,7 +5,7 @@ Feature: CoffeeScript transpiler
5
5
  """
6
6
  paths:
7
7
  - app
8
- compile:
8
+ build:
9
9
  - app.js
10
10
  """
11
11
  And a file named "app/app.coffee" with:
@@ -5,7 +5,7 @@ Feature: SASS transpiler
5
5
  """
6
6
  paths:
7
7
  - app
8
- compile:
8
+ build:
9
9
  - styles/main.css
10
10
  """
11
11
  And a file named "app/styles/main.sass" with:
@@ -4,7 +4,7 @@ end
4
4
 
5
5
 
6
6
  When /^I build$/ do
7
- run_simple 'zassets compile'
7
+ run_simple 'zassets build'
8
8
  end
9
9
 
10
10
 
@@ -33,3 +33,9 @@ Then /^the built file "([^"]*)" should match \/([^\/]*)\/$/ do |path, content|
33
33
  IO.read(Dir[path].first).should =~ regexp
34
34
  end
35
35
  end
36
+
37
+ Then /^it should build$/ do
38
+ prep_for_fs_check do
39
+ File.exist?('public/assets/manifest.json').should be_true
40
+ end
41
+ end
@@ -3,7 +3,7 @@ require 'coffee_script'
3
3
 
4
4
  module ZAssets
5
5
  autoload :CLI, 'zassets/cli'
6
- autoload :Compiler, 'zassets/compiler'
6
+ autoload :Builder, 'zassets/builder'
7
7
  autoload :Config, 'zassets/config'
8
8
  autoload :MemoryFile, 'zassets/memory_file'
9
9
  autoload :Server, 'zassets/server'
@@ -1,7 +1,7 @@
1
1
  require 'sprockets'
2
2
 
3
3
  module ZAssets
4
- class Compiler
4
+ class Builder
5
5
  MANIFEST_FILENAME = 'manifest.json'
6
6
 
7
7
  attr_writer :manifest
@@ -10,8 +10,8 @@ module ZAssets
10
10
  @config = config
11
11
  end
12
12
 
13
- def compile
14
- manifest.compile(@config[:compile])
13
+ def build
14
+ manifest.compile(@config[:build])
15
15
  end
16
16
 
17
17
  def manifest
@@ -19,7 +19,7 @@ module ZAssets
19
19
  end
20
20
 
21
21
  def manifest_path
22
- [@config[:compile_path], MANIFEST_FILENAME].join '/'
22
+ [@config[:build_path], MANIFEST_FILENAME].join '/'
23
23
  end
24
24
 
25
25
  def environment
@@ -2,17 +2,44 @@ require 'optparse'
2
2
 
3
3
  module ZAssets
4
4
  class CLI
5
- attr_reader :options
5
+ ACTIONS = %w(build serve)
6
+
7
+ attr_reader :options, :action
6
8
 
7
9
  def initialize(args, stdout = $stdout)
8
10
  @stdout = stdout
9
- @options = args_parse! args
11
+ @action = :build
12
+ args_parse! args
13
+ end
14
+
15
+ def config
16
+ @config ||= Config.new @options
17
+ end
18
+
19
+ def run
20
+ case @action
21
+ when :serve
22
+ server.run
23
+ when :build
24
+ builder.build
25
+ end
26
+ end
27
+
28
+ def builder
29
+ @builder ||= Builder.new config
30
+ end
31
+
32
+ def server
33
+ @server ||= Server.new config
10
34
  end
11
35
 
36
+
37
+ private
38
+
12
39
  def args_parse!(args)
13
40
  options = {}
14
41
  parser = OptionParser.new do |o|
15
- o.banner = "Usage: #{File.basename $0} [options] compile|serve"
42
+ o.banner = "Usage: #{File.basename $0} [options] [build|serve]"
16
43
 
17
44
  o.on '-v', '--verbose', 'Enable verbose mode' do |v|
18
45
  options[:verbose] = v
@@ -53,35 +80,8 @@ module ZAssets
53
80
  exit 64
54
81
  end
55
82
 
56
- if args.last && %w(compile serve).include?(args.last)
57
- options[:action] = args.last.to_sym
58
- else
59
- @stdout.puts parser
60
- exit 64
61
- end
62
-
63
- options
64
- end
65
-
66
- def config
67
- @config ||= Config.new @options
68
- end
69
-
70
- def run
71
- case config[:action]
72
- when :serve
73
- server.run
74
- when :compile
75
- compiler.compile
76
- end
77
- end
78
-
79
- def compiler
80
- @compiler ||= Compiler.new config
81
- end
82
-
83
- def server
84
- @server ||= Server.new config
83
+ @options = options
84
+ @action = args.last.to_sym if args.last && ACTIONS.include?(args.last)
85
85
  end
86
86
  end
87
87
  end
@@ -14,8 +14,8 @@ module ZAssets
14
14
  base_url: '/assets',
15
15
  paths: [],
16
16
  public_path: 'public',
17
- compile_path: 'public/assets',
18
- compile: []
17
+ build_path: 'public/assets',
18
+ build: []
19
19
  }
20
20
 
21
21
  def initialize(options = {})
@@ -1,3 +1,3 @@
1
1
  module ZAssets
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
@@ -1,38 +1,38 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module ZAssets
4
- describe Compiler do
5
- let(:config) { Config.new }
6
- subject(:compiler) { Compiler.new(config) }
4
+ describe Builder do
5
+ let(:config) { Config.new }
6
+ subject(:builder) { Builder.new(config) }
7
7
 
8
- describe '#compile' do
8
+ describe '#build' do
9
9
  it 'compiles the manifest' do
10
- compiler.manifest = double('manifest')
11
- compiler.manifest.should_receive :compile
12
- compiler.compile
10
+ builder.manifest = double('manifest')
11
+ builder.manifest.should_receive :compile
12
+ builder.build
13
13
  end
14
14
  end
15
15
 
16
16
  describe '#manifest' do
17
17
  it 'builds a sprockets manifest' do
18
18
  Sprockets::Manifest.should_receive(:new).with(
19
- compiler.environment,
20
- compiler.manifest_path
19
+ builder.environment,
20
+ builder.manifest_path
21
21
  )
22
- compiler.manifest
22
+ builder.manifest
23
23
  end
24
24
 
25
25
  it 'returns the sprockets manifest' do
26
26
  manifest = double('manifest')
27
27
  Sprockets::Manifest.stub(:new) { manifest }
28
- compiler.manifest.should == manifest
28
+ builder.manifest.should == manifest
29
29
  end
30
30
  end
31
31
 
32
32
  describe '#manifest_path' do
33
33
  it 'returns the manifest file path' do
34
- compiler.manifest_path.should == File.join(
35
- config[:compile_path],
34
+ builder.manifest_path.should == File.join(
35
+ config[:build_path],
36
36
  'manifest.json'
37
37
  )
38
38
  end
@@ -41,13 +41,13 @@ module ZAssets
41
41
  describe '#environment' do
42
42
  it 'builds a sprockets env' do
43
43
  SprocketsEnv.should_receive(:new).with(config)
44
- compiler.environment
44
+ builder.environment
45
45
  end
46
46
 
47
47
  it 'returns the sprockets env' do
48
48
  environment = double('environment')
49
49
  SprocketsEnv.stub(:new) { environment }
50
- compiler.environment.should == environment
50
+ builder.environment.should == environment
51
51
  end
52
52
  end
53
53
  end
@@ -5,78 +5,94 @@ module ZAssets
5
5
  let(:args) { ['serve'] }
6
6
  subject(:cli) { CLI.new(args) }
7
7
 
8
- context 'action arguments parsing' do
9
- it 'parses the action' do
10
- cli.options[:action].should == :serve
11
- end
12
- end
13
-
14
- context 'option arguments parsing ' do
15
- def with_option(option, value = nil)
16
- if value
17
- CLI.new [option, value, *args]
18
- else
19
- CLI.new [option, *args]
8
+ describe '#initialize' do
9
+ context 'action arguments parsing' do
10
+ it 'parses the action' do
11
+ cli.action.should == :serve
20
12
  end
21
- end
22
13
 
23
- it 'parses the -v option' do
24
- with_option('-v').options[:verbose].should be_true
25
- end
14
+ context 'when action is not provided' do
15
+ let(:args) { [] }
26
16
 
27
- it 'parses the -c option' do
28
- with_option('-c', 'config').options[:config_file].should == 'config'
17
+ it 'defaults to build' do
18
+ cli.action.should == :build
19
+ end
20
+ end
29
21
  end
30
22
 
31
- it 'parses the -o option' do
32
- with_option('-o', '::0').options[:host].should == '::0'
33
- end
23
+ context 'option arguments parsing ' do
24
+ def with_option(option, value = nil)
25
+ if value
26
+ CLI.new [option, value, *args]
27
+ else
28
+ CLI.new [option, *args]
29
+ end
30
+ end
34
31
 
35
- it 'parses the -p option' do
36
- with_option('-p', '9393').options[:port].should == '9393'
37
- end
32
+ it 'parses the -v option' do
33
+ with_option('-v').options[:verbose].should be_true
34
+ end
38
35
 
39
- it 'parses the -s option' do
40
- with_option('-s', 'thin').options[:server].should == 'thin'
41
- end
36
+ it 'parses the -c option' do
37
+ with_option('-c', 'config').options[:config_file].should == 'config'
38
+ end
42
39
 
43
- context '-h option' do
44
- let(:args) { ['-h'] }
45
- let(:output) { StringIO.new }
46
- subject(:cli) { CLI.new(args, output) }
40
+ it 'parses the -o option' do
41
+ with_option('-o', '::0').options[:host].should == '::0'
42
+ end
47
43
 
48
- it 'prints the usage help' do
49
- begin
50
- cli
51
- rescue SystemExit
52
- end
53
- output.string.should =~ /\AUsage: /
44
+ it 'parses the -p option' do
45
+ with_option('-p', '9393').options[:port].should == '9393'
54
46
  end
55
47
 
56
- it 'exits' do
57
- lambda { cli }.should raise_error SystemExit
48
+ it 'parses the -s option' do
49
+ with_option('-s', 'thin').options[:server].should == 'thin'
58
50
  end
59
- end
60
51
 
61
- context '-V option' do
62
- let(:args) { ['-V'] }
63
- let(:output) { StringIO.new }
64
- subject(:cli) { CLI.new(args, output) }
52
+ context '-h option' do
53
+ let(:args) { ['-h'] }
54
+ let(:output) { StringIO.new }
55
+ subject(:cli) { CLI.new(args, output) }
56
+
57
+ it 'prints the usage help' do
58
+ begin
59
+ cli
60
+ rescue SystemExit
61
+ end
62
+ output.string.should =~ /\AUsage: /
63
+ end
65
64
 
66
- it 'prints the version' do
67
- begin
68
- cli
69
- rescue SystemExit
65
+ it 'exits' do
66
+ lambda { cli }.should raise_error SystemExit
70
67
  end
71
- output.string.chomp.should == VERSION
72
68
  end
73
69
 
74
- it 'exits' do
75
- lambda { cli }.should raise_error SystemExit
70
+ context '-V option' do
71
+ let(:args) { ['-V'] }
72
+ let(:output) { StringIO.new }
73
+ subject(:cli) { CLI.new(args, output) }
74
+
75
+ it 'prints the version' do
76
+ begin
77
+ cli
78
+ rescue SystemExit
79
+ end
80
+ output.string.chomp.should == VERSION
81
+ end
82
+
83
+ it 'exits' do
84
+ lambda { cli }.should raise_error SystemExit
85
+ end
76
86
  end
77
87
  end
78
88
  end
79
89
 
90
+ describe '#action' do
91
+ it 'return the current action' do
92
+ cli.action.should == args.last.to_sym
93
+ end
94
+ end
95
+
80
96
  describe '#config' do
81
97
  it 'builds a config' do
82
98
  Config.should_receive(:new).with(cli.options)
@@ -100,28 +116,28 @@ module ZAssets
100
116
  end
101
117
  end
102
118
 
103
- context 'compiler action' do
104
- let(:args) { ['compile'] }
119
+ context 'build action' do
120
+ let(:args) { ['build'] }
105
121
 
106
- it 'runs the compiler' do
107
- compiler = double('compiler')
108
- cli.stub(:compiler) { compiler }
109
- compiler.should_receive :compile
122
+ it 'runs the builder' do
123
+ builder = double('builder')
124
+ cli.stub(:builder) { builder }
125
+ builder.should_receive :build
110
126
  cli.run
111
127
  end
112
128
  end
113
129
  end
114
130
 
115
- describe '#compiler' do
116
- it 'builds a compiler' do
117
- Compiler.should_receive(:new).with(cli.config)
118
- cli.compiler
131
+ describe '#builder' do
132
+ it 'builds a builder' do
133
+ Builder.should_receive(:new).with(cli.config)
134
+ cli.builder
119
135
  end
120
136
 
121
- it 'returns the compiler' do
122
- compiler = double('compiler')
123
- Compiler.stub(:new) { compiler }
124
- cli.compiler.should == compiler
137
+ it 'returns the builder' do
138
+ builder = double('builder')
139
+ Builder.stub(:new) { builder }
140
+ cli.builder.should == builder
125
141
  end
126
142
  end
127
143
 
@@ -67,12 +67,12 @@ module ZAssets
67
67
  config.default_options[:public_path].should == 'public'
68
68
  end
69
69
 
70
- it 'sets compile_path to public/assets directory' do
71
- config.default_options[:compile_path].should == 'public/assets'
70
+ it 'sets build_path to public/assets directory' do
71
+ config.default_options[:build_path].should == 'public/assets'
72
72
  end
73
73
 
74
- it 'sets compile empty' do
75
- config.default_options[:compile].should == []
74
+ it 'sets build empty' do
75
+ config.default_options[:build].should == []
76
76
  end
77
77
  end
78
78
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zassets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -189,6 +189,7 @@ files:
189
189
  - bin/zassets
190
190
  - features/builder/build.feature
191
191
  - features/builder/manifest.feature
192
+ - features/cli/default_action.feature
192
193
  - features/cli/usage.feature
193
194
  - features/cli/version.feature
194
195
  - features/config/file.feature
@@ -208,8 +209,8 @@ files:
208
209
  - features/support/env_cucumber-doc_string.rb
209
210
  - features/support/env_server.rb
210
211
  - lib/zassets.rb
212
+ - lib/zassets/builder.rb
211
213
  - lib/zassets/cli.rb
212
- - lib/zassets/compiler.rb
213
214
  - lib/zassets/config.rb
214
215
  - lib/zassets/exceptions.rb
215
216
  - lib/zassets/memory_file.rb
@@ -223,8 +224,8 @@ files:
223
224
  - spec/spec_helper.rb
224
225
  - spec/support/fixtures_helpers.rb
225
226
  - spec/zassets-plugins-dummy.rb
227
+ - spec/zassets/builder_spec.rb
226
228
  - spec/zassets/cli_spec.rb
227
- - spec/zassets/compiler_spec.rb
228
229
  - spec/zassets/config_spec.rb
229
230
  - spec/zassets/memory_file_spec.rb
230
231
  - spec/zassets/server_spec.rb
@@ -253,7 +254,7 @@ rubyforge_project:
253
254
  rubygems_version: 1.8.23
254
255
  signing_key:
255
256
  specification_version: 3
256
- summary: zassets-0.2.3
257
+ summary: zassets-0.2.4
257
258
  test_files:
258
259
  - spec/fixtures/assets/app.js
259
260
  - spec/fixtures/config/zassets.yaml
@@ -262,8 +263,8 @@ test_files:
262
263
  - spec/spec_helper.rb
263
264
  - spec/support/fixtures_helpers.rb
264
265
  - spec/zassets-plugins-dummy.rb
266
+ - spec/zassets/builder_spec.rb
265
267
  - spec/zassets/cli_spec.rb
266
- - spec/zassets/compiler_spec.rb
267
268
  - spec/zassets/config_spec.rb
268
269
  - spec/zassets/memory_file_spec.rb
269
270
  - spec/zassets/server_spec.rb