snowball 0.1.5 → 0.1.6

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.
@@ -11,6 +11,10 @@ var argv = optimist
11
11
  .option('help', {
12
12
  desc : 'Show this help'
13
13
  })
14
+ .option('raw', {
15
+ alias : 'r',
16
+ desc : 'Just compile entry file, without using browserify.'
17
+ })
14
18
  .option('require', {
15
19
  alias : 'r',
16
20
  desc : 'A module name or file to bundle.require()\n'
@@ -38,6 +42,27 @@ var argv = optimist
38
42
  if (argv.help) {
39
43
  return optimist.showHelp()
40
44
  }
45
+ if (argv.raw) {
46
+ var compilers = {
47
+ coffee: function (data) {
48
+ var coffee = require("coffee-script");
49
+ return coffee.compile(data);
50
+ }
51
+ };
52
+ (argv._.concat(argv.entry || [])).forEach(function (entry) {
53
+ // todo: keep a map of extension => compiler instead (in order to support jade compiling too)
54
+ var compile = compilers[path.extname(entry).replace(/^\./, "")];
55
+ fs.readFile(entry, function (err, data) {
56
+ if (err) throw err;
57
+ if (compile) data = compile(data.toString());
58
+ process.stdout.write("\n");
59
+ process.stdout.write(data);
60
+ process.stdout.write("\n");
61
+ });
62
+ });
63
+ return;
64
+ }
65
+
41
66
 
42
67
  // Parse argv.env properly
43
68
  // turns argv.env strings like ['FOO=bar', 'BAZ=qux', ...] into an object of { FOO: 'bar', BAZ:'qux' }
@@ -2,50 +2,50 @@
2
2
  module Snowball
3
3
  class Config
4
4
  class Builder
5
- def initialize(config)
5
+ def initialize(config = {})
6
6
  @config = config
7
+ @config[:extensions] ||= [:js, :coffee]
8
+ @config[:source_paths] ||= []
9
+ @config[:raw] ||= []
10
+ @config[:source] ||= []
11
+ @config[:includes] ||= []
12
+ @config[:ignores] = []
13
+ @config[:env] ||= {}
14
+ @config[:prelude] ||= true
7
15
  end
8
16
  def http_path(path)
9
- @config.http_path = path
17
+ @config[:http_path] = path
10
18
  end
11
19
  alias_method :set_serve_path, :http_path # todo: deprecate
12
20
  def source_path(path)
13
- @config.source_paths << File.expand_path(path)
21
+ @config[:source_paths] << File.expand_path(path)
14
22
  end
15
23
 
16
24
  alias_method :add_load_path, :source_path # todo: deprecate
17
25
  def raw(glob_string)
18
- @config.raw << glob_string
26
+ @config[:raw] << glob_string
27
+ end
28
+
29
+ def source(glob_string)
30
+ @config[:source] << glob_string
19
31
  end
20
32
 
21
33
  def ignore(node_module)
22
- @config.ignores << node_module
34
+ @config[:ignores] << node_module
23
35
  end
24
36
 
25
37
  def setenv(*args)
26
- @config.env.merge!(args.first) and return if args.size == 1
27
- @config.env[args.first] = args[1]
38
+ @config[:env].merge!(args.first) and return if args.size == 1
39
+ @config[:env][args.first] = args[1]
28
40
  end
29
41
 
30
42
  def include(node_module)
31
- @config.includes << node_module
43
+ @config[:includes] << node_module
32
44
  end
33
45
 
34
46
  def prelude(bool)
35
- @config.prelude = bool
47
+ @config[:prelude] = bool
36
48
  end
37
49
  end
38
-
39
- attr_accessor :http_path, :source_paths, :raw, :extensions, :includes, :ignores, :prelude, :env
40
-
41
- def initialize
42
- @extensions = [:js, :coffee]
43
- @source_paths = []
44
- @raw = []
45
- @includes = []
46
- @ignores = []
47
- @env = {}
48
- @prelude = true
49
- end
50
50
  end
51
51
  end
@@ -8,16 +8,17 @@ module Snowball
8
8
  def self.roll(entry, opts)
9
9
  args = []
10
10
 
11
- ignores = opts.ignores.dup
11
+ ignores = opts[:ignores].dup
12
12
  ignores.unshift *%w(jsdom xmlhttprequest location navigator)
13
13
  ignores.uniq!
14
14
 
15
15
  args << ignores.map { |node_module| "--ignore #{node_module}" }.join(" ")
16
- args << opts.includes.map { |node_module| "--require #{node_module}" }.join(" ")
17
- args << "--prelude #{!!opts.prelude}"
16
+ args << opts[:includes].map { |node_module| "--require #{node_module}" }.join(" ")
17
+ args << "--prelude #{!!opts[:prelude]}"
18
18
  args << "--entry #{entry}"
19
+ args << "--raw" if opts[:raw]
19
20
 
20
- args += (opts.env || {}).map do |k,v|
21
+ args += (opts[:env] || {}).map do |k,v|
21
22
  "--env #{k}=#{v}"
22
23
  end
23
24
 
@@ -4,8 +4,8 @@ module Sinatra
4
4
  module Snowball
5
5
  # Resolves a file relative to the source path
6
6
  def self.resolve_file(config, file)
7
- source_paths = config.source_paths
8
- extensions = config.extensions
7
+ source_paths = config[:source_paths]
8
+ extensions = config[:extensions]
9
9
 
10
10
  source_paths.each do |source_path|
11
11
  try_file = File.expand_path(File.join(source_path, file))
@@ -27,29 +27,30 @@ module Sinatra
27
27
  end
28
28
 
29
29
  def snowball(&block)
30
- config = ::Snowball::Config.new
30
+ config = {}
31
31
  builder = ::Snowball::Config::Builder.new(config)
32
32
  builder.send(:instance_eval, &block)
33
33
  self.set :snowball, config
34
- self.get "#{config.http_path}/*" do |bundle|
34
+ self.get "#{config[:http_path]}/*" do |bundle|
35
35
  begin
36
36
  entryfile = Snowball.resolve_file(config, bundle)
37
37
  rescue Errno::ENOENT => e
38
38
  halt 404, "File #{bundle} not found"
39
39
  end
40
40
 
41
- if File.extname(bundle) != '.js' or config.raw.any? { |glob_str| File.fnmatch(glob_str, entryfile) }
41
+ if File.extname(bundle) != '.js' or config[:source].any? { |glob_str| File.fnmatch(glob_str, entryfile) }
42
42
  send_file entryfile
43
43
  else
44
+ raw = config[:raw].any? { |glob_str| File.fnmatch(glob_str, entryfile) }
44
45
  content_type :js
45
- [200, ::Snowball::Roller.roll(*[entryfile, config].compact)]
46
+ [200, ::Snowball::Roller.roll(*[entryfile, config.merge({:raw => raw})].compact)]
46
47
  end
47
48
  end
48
49
  end
49
50
 
50
51
  module Helpers
51
52
  def javascript_path(file)
52
- "#{self.settings.snowball.http_path}/#{file}.js"
53
+ "#{self.settings.snowball[:http_path]}/#{file}.js"
53
54
  end
54
55
 
55
56
  def javascript_tag(file, opts={})
@@ -1,3 +1,3 @@
1
1
  module Snowball
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -0,0 +1 @@
1
+ console.log("That is awesome!");
@@ -0,0 +1 @@
1
+ alert "I knew it!" if elvis?
@@ -4,7 +4,8 @@ class SnowballApp < Sinatra::Base
4
4
  http_path "/js"
5
5
  source_path "spec/fixtures/js"
6
6
  source_path "spec/fixtures/js/food"
7
- raw "*/food/steak.js"
7
+ raw "*/js/raw-2.js"
8
+ raw "*/js/raw.coffee"
8
9
  end
9
10
 
10
11
  get "/javascript_tag" do
@@ -31,12 +31,24 @@ describe "SnowballApp" do
31
31
  last_response.body.should match compiled
32
32
  end
33
33
 
34
- it "serves the coffee-script file raw if requested with .coffee as extension" do
34
+ it "serves the coffee-script file as source if requested with .coffee as extension" do
35
35
  get "/js/require.coffee"
36
36
  last_response.status.should eq 200
37
37
  last_response.body.should match Regexp.escape("test = ->")
38
38
  end
39
39
 
40
+ it "serves the javascript entry raw (not browserified) it matches the configured glob strings" do
41
+ get "/js/raw-2.js"
42
+ last_response.status.should eq 200
43
+ last_response.body.should match Regexp.escape('console.log("That is awesome!");')
44
+ end
45
+
46
+ it "serves the coffeescript entry raw (combiled, but not browserified) it matches the configured glob strings" do
47
+ get "/js/raw.js"
48
+ last_response.status.should eq 200
49
+ last_response.body.should match Regexp.escape('alert("I knew it!");')
50
+ end
51
+
40
52
  it "includes transitive dependencies" do
41
53
  get "/js/require.js"
42
54
  last_response.status.should eq 200
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snowball
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
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-01-21 00:00:00.000000000 Z
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -123,6 +123,8 @@ files:
123
123
  - spec/fixtures/js/hello.jade
124
124
  - spec/fixtures/js/pastry/tart.js
125
125
  - spec/fixtures/js/pastry/tartlet.coffee
126
+ - spec/fixtures/js/raw-2.js
127
+ - spec/fixtures/js/raw.coffee
126
128
  - spec/fixtures/js/require-error.js
127
129
  - spec/fixtures/js/require.coffee
128
130
  - spec/fixtures/js/some.coffee
@@ -164,6 +166,8 @@ test_files:
164
166
  - spec/fixtures/js/hello.jade
165
167
  - spec/fixtures/js/pastry/tart.js
166
168
  - spec/fixtures/js/pastry/tartlet.coffee
169
+ - spec/fixtures/js/raw-2.js
170
+ - spec/fixtures/js/raw.coffee
167
171
  - spec/fixtures/js/require-error.js
168
172
  - spec/fixtures/js/require.coffee
169
173
  - spec/fixtures/js/some.coffee