half-pipe 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b1ff38df667bbc3470faa09055259c084d30f6d
4
- data.tar.gz: 8e8e5c065f2ba50d58a0a9e1679ef73d4f77f456
3
+ metadata.gz: c8320c78751a0859e14e464daf98a1df81b9834d
4
+ data.tar.gz: 53a5705861ec0f78dd35a3be32ec7d8e7dd0da14
5
5
  SHA512:
6
- metadata.gz: 3fc3909bb624f799182679940bed0d2af151b0ad3dfeb9ee09d9964543096f660128bd8171a3da37a63df5d9df01b7d5a052060fc854c46dad02793065f24db7
7
- data.tar.gz: fa22616f76f43f524104c69f9753b5aa31818f60615b66d4bee5a25cfcf8881e2ecf958ee07e8dac9e815186d0f56e070db36f7054dda729805513558ab224a8
6
+ metadata.gz: 6df438586c47a93b17d423a08527a018d9e217425da8144e60879f1bcb3f11c1f1511bfd4b7f92bb51ca850b4e1759e160847eaedef2e71a1551cc3b4f6dea66
7
+ data.tar.gz: cf4c9619d7f7ec7a96efd63c57bd2130b4018992bc547dd3b1dc3b2998414118ace29f98de273173a21fc5ddfd956a070fbfded5521b769a466eb07fca95d598
data/README.md CHANGED
@@ -91,6 +91,10 @@ In this early release if you want to configure anything, you'll have to manually
91
91
 
92
92
  ## History
93
93
 
94
+ ### 07/22/2013 v0.2.0
95
+
96
+ - Removes dependency on rack-asset-compiler and embeds the code in this gem
97
+
94
98
  ### 07/19/2013 v0.1.0
95
99
 
96
100
  - Override Rails' `rake assets:precompile` to run `grunt build` for easier deployments
@@ -17,6 +17,5 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency "rack-asset-compiler"
21
20
  gem.add_dependency "sass"
22
21
  end
@@ -1,5 +1,5 @@
1
1
  module Half
2
2
  module Pipe
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -0,0 +1,83 @@
1
+ module Rack
2
+ class AssetCompiler
3
+ attr_accessor :url, :source_dir, :source_extension
4
+
5
+ F = ::File
6
+
7
+ def initialize(app, options={}, &block)
8
+ @app = app
9
+
10
+ options = {
11
+ :compiler => block,
12
+ :source_dir => Dir.pwd,
13
+ :url => '/',
14
+ :cache => ENV['RACK_ENV'] == 'production'
15
+ }.merge(options)
16
+
17
+ @compiler = options[:compiler]
18
+ @source_dir = options[:source_dir]
19
+ @url = options[:url]
20
+ @source_extension = options[:source_extension]
21
+ @content_type = options[:content_type]
22
+
23
+ @cache_ttl = options[:cache]
24
+
25
+ # Default cache duration is 1 week
26
+ if(@cache_ttl && !@cache_ttl.kind_of?(Integer))
27
+ @cache_ttl = 60 * 60 * 24 * 7
28
+ end
29
+ end
30
+
31
+ def response(status, body)
32
+ body += "\r\n"
33
+ [status, {"Content-Type" => 'text/plain',
34
+ "Content-Length" => body.size.to_s},
35
+ [body]]
36
+ end
37
+
38
+ def compile(source_file)
39
+ if @compiler
40
+ @compiler.call(source_file)
41
+ else
42
+ raise "Missing compiler"
43
+ end
44
+ end
45
+
46
+ def call(env)
47
+ request_path = Utils.unescape(env["PATH_INFO"])
48
+ return response( 403, 'Forbidden') if request_path.include? ".."
49
+
50
+ match_parts = url.split('/').select{ |str| str.length > 0 }
51
+ request_parts = request_path.split('/').select{ |str| str.length > 0 }
52
+
53
+ if(request_parts.take(match_parts.length) == match_parts)
54
+ request_base = request_parts[match_parts.length..-1]
55
+
56
+ # Directory listsings not supported
57
+ return response( 404, 'Not found') if F.directory? F.join(source_dir, request_base)
58
+
59
+ if source_extension
60
+ # Swap in the source file extension if given
61
+ request_base[-1].sub!(/\.\w+$/, '.' + source_extension)
62
+ end
63
+ source_file = F.join(source_dir, request_base)
64
+
65
+ if F.exists?(source_file)
66
+ body = compile(source_file)
67
+
68
+ @content_type ||= Rack::Mime.mime_type(F.extname(source_file))
69
+
70
+ headers = {
71
+ 'Content-Type' => @content_type
72
+ }
73
+
74
+ return [200, headers, [body]]
75
+ end
76
+ end
77
+
78
+ @app.call(env)
79
+ end
80
+
81
+ end
82
+ end
83
+
@@ -0,0 +1,44 @@
1
+ require 'rack/asset_compiler'
2
+ require 'coffee-script'
3
+
4
+ module Rack
5
+ class CoffeeCompiler < AssetCompiler
6
+ LOCK = Mutex.new
7
+
8
+ def initialize(app, options={})
9
+ options = {
10
+ :url => '/javascripts',
11
+ :content_type => 'text/javascript',
12
+ :source_extension => 'coffee',
13
+ :alert_on_error => ENV['RACK_ENV'] != 'production',
14
+ :lock => LOCK
15
+ }.merge(options)
16
+
17
+ @alert_on_error = options[:alert_on_error]
18
+ @lock = options[:lock]
19
+ super
20
+ end
21
+
22
+ def compile(source_file)
23
+ if @lock
24
+ @lock.synchronize{ unsynchronized_compile(source_file) }
25
+ else
26
+ unsynchronized_compile(source_file)
27
+ end
28
+ end
29
+
30
+ def unsynchronized_compile(source_file)
31
+ begin
32
+ CoffeeScript.compile(::File.read(source_file))
33
+ rescue CoffeeScript::CompilationError => e
34
+ if @alert_on_error
35
+ error_msg = "CoffeeScript compilation error in #{source_file}.coffee:\n\n #{e.to_s}"
36
+ "window.alert(#{error_msg.to_json});"
37
+ else
38
+ raise e
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
@@ -0,0 +1,44 @@
1
+ require 'rack/asset_compiler'
2
+ require 'sass'
3
+
4
+ module Rack
5
+ class SassCompiler < AssetCompiler
6
+ attr_accessor :sass_options
7
+
8
+ def initialize(app, options={})
9
+ options
10
+
11
+ options = {
12
+ :url => '/stylesheets',
13
+ :content_type => 'text/css',
14
+ }.merge(options)
15
+
16
+ options[:sass_options] ||= {}
17
+ options[:sass_options] = {
18
+ :syntax => :scss,
19
+ :cache => false
20
+ }.merge(options[:sass_options])
21
+
22
+ @sass_options = options[:sass_options]
23
+ options[:source_extension] ||= @sass_options[:syntax].to_s
24
+ super
25
+ end
26
+
27
+ def get_load_paths(src_dir)
28
+ paths = [src_dir]
29
+ if defined?(Compass::Frameworks)
30
+ Compass::Frameworks::ALL.each do |framework|
31
+ paths << framework.stylesheets_directory if ::File.exists?(framework.stylesheets_directory)
32
+ end
33
+ end
34
+ paths
35
+ end
36
+
37
+ def compile(source_file)
38
+ @sass_options[:load_paths] ||= []
39
+ @sass_options[:load_paths] = @sass_options[:load_paths] | get_load_paths(source_dir)
40
+ Sass::Engine.new(::File.read(source_file), @sass_options).render
41
+ end
42
+ end
43
+ end
44
+
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: half-pipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Fiorini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-19 00:00:00.000000000 Z
11
+ date: 2013-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rack-asset-compiler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: sass
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -120,7 +106,10 @@ files:
120
106
  - lib/half-pipe.rb
121
107
  - lib/half-pipe/rails.rb
122
108
  - lib/half-pipe/version.rb
109
+ - lib/rack/asset_compiler.rb
110
+ - lib/rack/coffee_compiler.rb
123
111
  - lib/rack/half-pipe.rb
112
+ - lib/rack/sass_compiler.rb
124
113
  - lib/sass/half_pipe_functions.rb
125
114
  - lib/sass/importers/bower_importer.rb
126
115
  - lib/tasks/assets.rake