sinatra-asset-snack 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjZiMDU1ZjkzZmE0OTEyNmMwYmQ3OWM5MWJmYTcwNmY2YWVlMWExMA==
4
+ ZGMyNDljMmRiZDJkMDFhODIzNDFjMWEyMzNjMzc5YTE5YmYxN2RmMw==
5
5
  data.tar.gz: !binary |-
6
- ZDViM2MzNzdlOWViODNiMDgyZGM1ZDdjODZlYWU5YTAxOWQ1N2EyMw==
6
+ OTY5N2VlZjA2OTM3ZGNmNTdkYmViMjI5YWQzNGE3MDBkMTVkMTgyZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZWJmMjBjMzk3ZWQwODBjYzZiZmJkYjRhZWZlYzMyOTk2NDQ4ZDI0MmEwMTY2
10
- NDYwMjU0NTFjMzk3YzJiMzg4MmY3OTYwNmFmN2VkYjFkMjQxN2U3YjA0OWJi
11
- N2VlYzE5OWY1YjY3ZjhmNWU4YWQ2MGI3ZmZmYjU4Y2FkY2QwYzk=
9
+ NDM2NGFmNzU1NDFkOTNiZDk2MzdlNjg5NGRlMjI3MmZhNTQwYjAyZGNhOTQ1
10
+ MDA1NTZjYWEzOWNmMzAwZWNlYjM2ZjA0NGExZjNkZmEyMTYzNDNiMDkwZDhk
11
+ MmU4M2JmMjViYWQzYWYzNzFiYmIyZjFiNDYyNjY0ZWQyYTQ3YjU=
12
12
  data.tar.gz: !binary |-
13
- NzBkNDFiNTA3MjgzYjc4YmJhMTEwNWEyZGEzODZmY2JlZWRkYjRmYjVjYTE3
14
- NjE4M2U2OGQyYjBmNDcwNzA0MWQ1YWU3YzI3Mzk5MTc1NDUxODRmN2ZkM2Y0
15
- NGE3NDYwMGIyNGYzYjc0ODUyNGUxMGE2NzQyY2FmODFlZTlkZjk=
13
+ OTcyNGMwMDdiZTVjM2VjYzg3MTBlZWM1NTc3ZDA3Y2M3ZTE2ZTFkNjFjMjkw
14
+ MjEyYzk3YzBjMjlmYjkzYTI3OTQ4NzNiNDhlYTUyMjBmNjM1YzJiMTMyNjkw
15
+ M2NiZTQ4YjM4NWQ4OTU1YzY3NjQwMGU4NTg5ZmRjYzcxNTk3MGQ=
@@ -1,7 +1,7 @@
1
1
  module Sinatra
2
2
  module AssetSnack
3
3
  class << self
4
- attr_reader :compilers
4
+ attr_reader :compilers, :configuration
5
5
 
6
6
  def registered(app)
7
7
  app.extend ClassMethods
@@ -9,6 +9,10 @@ module Sinatra
9
9
  app.send(:helpers, Helpers)
10
10
  end
11
11
 
12
+ def configure(&block)
13
+ @configuration = Configuration.new(&block)
14
+ end
15
+
12
16
  def register_compiler(compiler, handled_extensions)
13
17
  @compilers ||= {}
14
18
  handled_extensions.each do |ext|
@@ -18,7 +22,7 @@ module Sinatra
18
22
 
19
23
  def compiler_for(file_path)
20
24
  ext = (File.extname(file_path) || '.').downcase[1..-1]
21
- @compilers[ext.to_sym] unless ext.nil?
25
+ @compilers[ext.to_sym]
22
26
  end
23
27
  end # self
24
28
 
@@ -6,6 +6,17 @@ module Sinatra
6
6
  class << self
7
7
  attr_reader :compiled_mime_type, :handled_extensions
8
8
 
9
+ def inherited(klass)
10
+ klass.send(:define_singleton_method, :key) do
11
+ short_name = name.split('::').last
12
+ short_name.gsub(/compiler\z/i, '').underscore.to_sym
13
+ end
14
+
15
+ klass.send(:define_singleton_method, :configuration) do
16
+ AssetSnack.configuration.compilers[klass.key]
17
+ end
18
+ end
19
+
9
20
  def compile_file(file_path)
10
21
  ext = File.extname(file_path).downcase[1..-1]
11
22
  return unless ext && handled_extensions.include?(ext.to_sym)
@@ -6,7 +6,7 @@ module Sinatra
6
6
  mime_type 'text/js'
7
7
 
8
8
  def compile(coffee_script)
9
- CoffeeScript.compile(coffee_script, {bare: true})
9
+ CoffeeScript.compile(coffee_script, self.class.configuration)
10
10
  end
11
11
  end
12
12
  end # Compilers
@@ -6,7 +6,7 @@ module Sinatra
6
6
  mime_type 'text/css'
7
7
 
8
8
  def compile(sass_script)
9
- Sass.compile(sass_script)
9
+ Sass.compile(sass_script, self.class.configuration)
10
10
  end
11
11
  end
12
12
  end # Compilers
@@ -0,0 +1,21 @@
1
+ module Sinatra
2
+ module AssetSnack
3
+ class Configuration
4
+ attr_reader :compilers
5
+
6
+ def initialize(&block)
7
+ instance_exec(self, &block) unless block.nil?
8
+ end
9
+
10
+ def compilers
11
+ @compilers ||= Hash.new.tap do |hash|
12
+ Compilers.constants.each do |compiler|
13
+ next if compiler == :AssetCompiler
14
+ hash[ Compilers.const_get(compiler).key ] = {}
15
+ end
16
+ end
17
+ end
18
+
19
+ end # Configuration
20
+ end # AssetSnack
21
+ end # Siantra
@@ -0,0 +1,13 @@
1
+ class String
2
+ unless instance_methods.include? :underscore
3
+ def underscore
4
+ word = self.dup
5
+ word.gsub!(/::/, '/')
6
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
7
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
8
+ word.tr!("-", "_")
9
+ word.downcase!
10
+ word
11
+ end
12
+ end
13
+ end
@@ -1,7 +1,7 @@
1
1
  module Sinatra
2
2
  module AssetSnack
3
3
  def self.version
4
- '0.1.0'
4
+ '0.1.1'
5
5
  end
6
6
  end # AssetSnack
7
- end # Sinatra
7
+ end # Sinatra
@@ -19,5 +19,15 @@ module Sinatra
19
19
  get '/javascript/application.js'
20
20
  last_response.headers['Content-Type'].must_equal 'text/js'
21
21
  end
22
+
23
+ it 'should allow compiler configuration' do
24
+ Sinatra::AssetSnack.configure do |config|
25
+ config.compilers[:coffee_script] = {bare: true}
26
+ end
27
+
28
+ get '/javascript/application.js'
29
+ puts last_response.body
30
+ last_response.body.wont_include ').call(this);'
31
+ end
22
32
  end
23
33
  end
@@ -8,13 +8,22 @@ module Sinatra
8
8
  let(:compiled) {
9
9
  <<-EOS
10
10
  (function() {
11
- var x;
11
+ (function() {
12
+ var x;
12
13
 
13
- return x = "test";
14
- });
14
+ return x = "test";
15
+ });
16
+
17
+ }).call(this);
15
18
  EOS
16
19
  }
17
20
 
21
+ before(:all) do
22
+ Sinatra::AssetSnack.configure do |config|
23
+ config.compilers[:coffee_script] = {}
24
+ end
25
+ end
26
+
18
27
  it 'must compile a coffeesript file' do
19
28
  subject.class.compile_file(file_path).must_equal compiled
20
29
  end
@@ -0,0 +1,10 @@
1
+ require './test/test_helper'
2
+ module Sinatra::AssetSnack
3
+ describe Configuration do
4
+
5
+ it 'should allow setting of compiler configuration' do
6
+ config = Configuration.new { |c| c.compilers[:coffee_script] = {bare: true} }
7
+ config.compilers[:coffee_script].must_equal(bare: true)
8
+ end
9
+ end
10
+ end
data/test/test_helper.rb CHANGED
@@ -9,6 +9,9 @@ require './lib/sinatra/asset_snack'
9
9
  MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
10
10
 
11
11
  class App < Sinatra::Base
12
+ Sinatra::AssetSnack.configure do |config|
13
+ config.compilers[:coffee_script] = {bare: true}
14
+ end
12
15
  register Sinatra::AssetSnack
13
16
  asset_map '/javascript/application.js', ['test/fixtures/**/*.coffee']
14
17
  asset_map '/stylesheets/application.css', ['test/fixtures/**/*.scss']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-asset-snack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Kitzelman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-28 00:00:00.000000000 Z
11
+ date: 2013-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -141,12 +141,16 @@ files:
141
141
  - lib/sinatra/asset_snack/compilers/asset_compiler.rb
142
142
  - lib/sinatra/asset_snack/compilers/coffee_script_compiler.rb
143
143
  - lib/sinatra/asset_snack/compilers/sass_compiler.rb
144
+ - lib/sinatra/asset_snack/configuration.rb
145
+ - lib/sinatra/asset_snack/extensions.rb
144
146
  - lib/sinatra/asset_snack/helpers.rb
145
147
  - lib/sinatra/asset_snack/version.rb
148
+ - releases/sinatra-asset-snack-0.1.0.gem
146
149
  - sinatra-asset-snack.gemspec
147
150
  - test/asset_snack_test.rb
148
151
  - test/compilers/coffee_script_compiler_test.rb
149
152
  - test/compilers/sass_compiler_test.rb
153
+ - test/configuration_test.rb
150
154
  - test/fixtures/test.coffee
151
155
  - test/fixtures/test.scss
152
156
  - test/fixtures/test_two.coffee