sinatra_asset_packager 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,7 @@ require "sprockets"
|
|
3
3
|
require "uglifier"
|
4
4
|
require "yui/compressor"
|
5
5
|
require "sinatra/base"
|
6
|
+
require "compass"
|
6
7
|
require "sinatra_asset_packager/version"
|
7
8
|
require "sinatra_asset_packager/helpers"
|
8
9
|
require "sinatra_asset_packager/routes"
|
@@ -11,8 +12,14 @@ require "sinatra_asset_packager/rake"
|
|
11
12
|
module SinatraAssetPackager
|
12
13
|
extend self
|
13
14
|
|
15
|
+
@@environment
|
16
|
+
|
17
|
+
PUBLIC_ASSETS_DIRECTORY = "public/assets"
|
18
|
+
CSS_EXTENSIONS = [".less", ".scss", ".sass", ".css"]
|
19
|
+
JS_EXTENSIONS = [".js", ".coffee"]
|
20
|
+
|
14
21
|
def environment(compress=false)
|
15
|
-
environment
|
22
|
+
@@environment ||= (Sprockets::Environment.new { |env|
|
16
23
|
env.append_path("app/assets/images")
|
17
24
|
env.append_path("app/assets/javascripts")
|
18
25
|
env.append_path("app/assets/stylesheets")
|
@@ -23,7 +30,38 @@ module SinatraAssetPackager
|
|
23
30
|
env.css_compressor = YUI::CssCompressor.new
|
24
31
|
end
|
25
32
|
})
|
33
|
+
end
|
34
|
+
|
35
|
+
def precompile
|
36
|
+
FileUtils.rm_rf(PUBLIC_ASSETS_DIRECTORY, secure: true)
|
37
|
+
FileUtils.mkdir_p(PUBLIC_ASSETS_DIRECTORY)
|
38
|
+
|
39
|
+
(CSS_EXTENSIONS + JS_EXTENSIONS).each do |extension|
|
40
|
+
files = Dir.glob("app/assets/**/**#{extension}")
|
41
|
+
files.each do |full_filepath|
|
42
|
+
regex_path = /app\/assets\/javascripts\/|app\/assets\/stylesheets\//
|
43
|
+
input_path = full_filepath.gsub(regex_path, '')
|
44
|
+
|
45
|
+
write_asset input_path, output_path(input_path, extension)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
FileUtils.cp_r(Dir['app/assets/images/*'], PUBLIC_ASSETS_DIRECTORY)
|
50
|
+
FileUtils.cp_r(Dir['app/assets/templates/*'], PUBLIC_ASSETS_DIRECTORY)
|
51
|
+
end
|
52
|
+
|
53
|
+
def write_asset(input_path, output_path)
|
54
|
+
puts output_path
|
55
|
+
final_output_path = [PUBLIC_ASSETS_DIRECTORY, output_path].join("/")
|
56
|
+
environment(true)[input_path].write_to(final_output_path)
|
57
|
+
rescue => e
|
58
|
+
puts e
|
59
|
+
puts "Asset #{input_path} failed to compile to #{output_path}"
|
60
|
+
end
|
26
61
|
|
27
|
-
|
62
|
+
def output_path(input_path, extension)
|
63
|
+
replacement_extension = '.js'
|
64
|
+
replacement_extension = '.css' if CSS_EXTENSIONS.include?(extension)
|
65
|
+
input_path.gsub(extension, replacement_extension)
|
28
66
|
end
|
29
|
-
end
|
67
|
+
end
|
@@ -1,29 +1,6 @@
|
|
1
1
|
namespace :assets do
|
2
2
|
desc "Precompile assets"
|
3
3
|
task :precompile do
|
4
|
-
|
5
|
-
dir = 'public/assets'
|
6
|
-
FileUtils.rm_rf(dir, secure: true)
|
7
|
-
|
8
|
-
CSS_EXTENSIONS = [".less", ".scss", ".sass", ".css"]
|
9
|
-
JS_EXTENSIONS = [".js", ".coffee"]
|
10
|
-
|
11
|
-
(CSS_EXTENSIONS + JS_EXTENSIONS).each do |extension|
|
12
|
-
files = Dir.glob("app/assets/**/**#{extension}")
|
13
|
-
files.each do |full_filepath|
|
14
|
-
regex_path = /app\/assets\/javascripts\/|app\/assets\/stylesheets\//
|
15
|
-
input_path = full_filepath.gsub(regex_path, '')
|
16
|
-
|
17
|
-
replacement_extension = '.js'
|
18
|
-
replacement_extension = '.css' if CSS_EXTENSIONS.include?(extension)
|
19
|
-
output_path = input_path.gsub(extension, replacement_extension)
|
20
|
-
|
21
|
-
puts output_path
|
22
|
-
assets[input_path].write_to("public/assets/#{output_path}")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
FileUtils.cp_r(Dir['app/assets/images/*'], 'public/assets')
|
27
|
-
FileUtils.cp_r(Dir['app/assets/templates/*'], 'public/assets')
|
4
|
+
SinatraAssetPackager.precompile
|
28
5
|
end
|
29
|
-
end
|
6
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra_asset_packager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2013-06-19 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &15219720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *15219720
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sinatra
|
27
|
-
requirement: &
|
27
|
+
requirement: &15219300 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *15219300
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sprockets
|
38
|
-
requirement: &
|
38
|
+
requirement: &15218880 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *15218880
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: uglifier
|
49
|
-
requirement: &
|
49
|
+
requirement: &15218460 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *15218460
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: yui-compressor
|
60
|
-
requirement: &
|
60
|
+
requirement: &15218040 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *15218040
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: json
|
71
|
-
requirement: &
|
71
|
+
requirement: &15217540 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,21 @@ dependencies:
|
|
76
76
|
version: 1.7.7
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *15217540
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: compass
|
82
|
+
requirement: &15217120 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *15217120
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: pry
|
82
|
-
requirement: &
|
93
|
+
requirement: &15216660 !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
95
|
requirements:
|
85
96
|
- - ! '>='
|
@@ -87,10 +98,10 @@ dependencies:
|
|
87
98
|
version: '0'
|
88
99
|
type: :development
|
89
100
|
prerelease: false
|
90
|
-
version_requirements: *
|
101
|
+
version_requirements: *15216660
|
91
102
|
- !ruby/object:Gem::Dependency
|
92
103
|
name: rspec
|
93
|
-
requirement: &
|
104
|
+
requirement: &15216240 !ruby/object:Gem::Requirement
|
94
105
|
none: false
|
95
106
|
requirements:
|
96
107
|
- - ! '>='
|
@@ -98,7 +109,7 @@ dependencies:
|
|
98
109
|
version: '0'
|
99
110
|
type: :development
|
100
111
|
prerelease: false
|
101
|
-
version_requirements: *
|
112
|
+
version_requirements: *15216240
|
102
113
|
description: Opinionated asset packaging for Sinatra done well.
|
103
114
|
email:
|
104
115
|
- scott@scottmotte.com
|
@@ -134,18 +145,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
145
|
- - ! '>='
|
135
146
|
- !ruby/object:Gem::Version
|
136
147
|
version: '0'
|
137
|
-
segments:
|
138
|
-
- 0
|
139
|
-
hash: 4110827005783106359
|
140
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
149
|
none: false
|
142
150
|
requirements:
|
143
151
|
- - ! '>='
|
144
152
|
- !ruby/object:Gem::Version
|
145
153
|
version: '0'
|
146
|
-
segments:
|
147
|
-
- 0
|
148
|
-
hash: 4110827005783106359
|
149
154
|
requirements: []
|
150
155
|
rubyforge_project:
|
151
156
|
rubygems_version: 1.8.11
|