pubba 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/CHANGES +19 -0
- data/lib/sinatra/pubba.rb +5 -2
- data/lib/sinatra/pubba/assets/configuration.rb +3 -1
- data/lib/sinatra/pubba/assets/minifier.rb +11 -0
- data/lib/sinatra/pubba/assets/yui_minifier.rb +28 -0
- data/lib/sinatra/pubba/site.rb +31 -10
- data/lib/sinatra/pubba/version.rb +1 -1
- data/pubba.gemspec +2 -1
- data/test/helper.rb +5 -11
- data/test/pubba/assets/test_minifier.rb +9 -0
- data/test/pubba/test_page.rb +10 -10
- data/test/pubba/test_site.rb +4 -0
- data/test/sinatra/app/assets/javascripts/custom/app.js +1 -0
- metadata +29 -15
data/.gitignore
CHANGED
data/CHANGES
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
master
|
2
2
|
|
3
|
+
0.3.0
|
4
|
+
|
5
|
+
* Include YUICompressor processing of stylesheets and javascripts
|
6
|
+
* Update to r18n-desktop 0.4.13 to address require issue
|
7
|
+
* Update disclaimer so it doesn't include the full path.
|
8
|
+
* Move processing of assets to before filter in dev and test mode
|
9
|
+
|
10
|
+
0.2.3
|
11
|
+
|
12
|
+
* Remove asset_id functionality. Dead code causing bugs.
|
13
|
+
|
14
|
+
0.2.2
|
15
|
+
|
16
|
+
* Asset compilation fix
|
17
|
+
|
18
|
+
0.2.1
|
19
|
+
|
20
|
+
* page_head_tags and page_body_tags implemented
|
21
|
+
|
3
22
|
0.2.0
|
4
23
|
|
5
24
|
* Ability to add external references
|
data/lib/sinatra/pubba.rb
CHANGED
@@ -7,12 +7,15 @@ require_relative 'pubba/html/helpers'
|
|
7
7
|
module Sinatra
|
8
8
|
module Pubba
|
9
9
|
def self.registered(app)
|
10
|
+
Site.configure(app)
|
11
|
+
|
10
12
|
if app.settings.development? || app.settings.test?
|
11
|
-
|
13
|
+
app.before do
|
14
|
+
Site.process(app)
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
app.helpers Sinatra::Pubba::HTML::Helpers
|
15
|
-
|
16
19
|
end
|
17
20
|
end # Pubba
|
18
21
|
end # Sinatra
|
@@ -5,13 +5,15 @@ module Sinatra
|
|
5
5
|
module Assets
|
6
6
|
class Configuration
|
7
7
|
attr_reader :yaml
|
8
|
+
attr_reader :name
|
8
9
|
|
9
10
|
def initialize(config_file)
|
11
|
+
@name = File.basename(config_file)
|
10
12
|
@yaml = Psych.load_file(config_file)
|
11
13
|
end
|
12
14
|
|
13
15
|
def global_config!
|
14
|
-
yaml.delete("global") || {}
|
16
|
+
@global_config ||= (yaml.delete("global") || {})
|
15
17
|
end
|
16
18
|
|
17
19
|
def process
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "yui/compressor"
|
2
|
+
require_relative 'minifier'
|
3
|
+
|
4
|
+
module Sinatra
|
5
|
+
module Pubba
|
6
|
+
module Assets
|
7
|
+
class YUIMinifier < Minifier
|
8
|
+
def self.minify(folder, handler)
|
9
|
+
compressor = get_compressor(handler)
|
10
|
+
Dir.glob("#{folder}/*.*") do |file|
|
11
|
+
contents = File.read(file)
|
12
|
+
File.open(file, "w") {|f| f.write(compressor.compress(contents))}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def self.get_compressor(handler)
|
19
|
+
case handler
|
20
|
+
when :js then YUI::JavaScriptCompressor.new
|
21
|
+
when :css then YUI::CssCompressor.new
|
22
|
+
else raise ArgumentError, "minify handler must be one of [:js, :css]"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end # YUIMinifier
|
26
|
+
end # Assets
|
27
|
+
end # Pubba
|
28
|
+
end # Sinatra
|
data/lib/sinatra/pubba/site.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'assets/configuration'
|
2
2
|
require_relative 'assets/sprockets_handler'
|
3
|
+
require_relative 'assets/yui_minifier'
|
3
4
|
require_relative 'page'
|
4
5
|
|
5
6
|
module Sinatra
|
@@ -9,7 +10,7 @@ module Sinatra
|
|
9
10
|
attr_reader :script_asset_folder, :style_asset_folder
|
10
11
|
attr_reader :script_public_folder, :style_public_folder
|
11
12
|
|
12
|
-
attr_reader :
|
13
|
+
attr_reader :asset_configuration, :asset_handler, :asset_minifier
|
13
14
|
attr_reader :disclaimer, :locale, :r18n_folder, :r18n_locale
|
14
15
|
|
15
16
|
|
@@ -18,26 +19,36 @@ module Sinatra
|
|
18
19
|
|
19
20
|
validate_settings(settings)
|
20
21
|
|
21
|
-
|
22
|
+
set_folder_defaults(settings)
|
22
23
|
|
23
24
|
maybe_init_r18n(settings)
|
24
25
|
|
25
26
|
# Load pubba_config
|
26
|
-
asset_configuration = Sinatra::Pubba::Assets::Configuration.new(settings.pubba_config)
|
27
|
+
@asset_configuration = Sinatra::Pubba::Assets::Configuration.new(settings.pubba_config)
|
28
|
+
|
29
|
+
@disclaimer = "// This file is automatically generated from the contents\n// in #{@asset_configuration.name}\n//\n"
|
27
30
|
|
28
31
|
# Set assset handler
|
29
32
|
configure_asset_handler(settings)
|
30
33
|
|
31
|
-
#
|
32
|
-
|
34
|
+
# Set compressor
|
35
|
+
configure_asset_compressor(settings)
|
33
36
|
|
34
37
|
# Process the remaining @pubba_config sections
|
35
38
|
asset_configuration.process do |p, config|
|
36
|
-
add_page(p, config)
|
39
|
+
add_page(p, config)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def process(app)
|
44
|
+
pages.each do |name, p|
|
45
|
+
p.assetize
|
37
46
|
end
|
38
47
|
|
39
48
|
# Write assets to public_folder
|
40
49
|
compile_assets(app)
|
50
|
+
|
51
|
+
minify_assets(app)
|
41
52
|
end
|
42
53
|
|
43
54
|
|
@@ -57,13 +68,11 @@ module Sinatra
|
|
57
68
|
end
|
58
69
|
end
|
59
70
|
|
60
|
-
def
|
71
|
+
def set_folder_defaults(settings)
|
61
72
|
@script_public_folder = File.join(settings.public_folder, 'javascripts')
|
62
73
|
@style_public_folder = File.join(settings.public_folder, 'stylesheets')
|
63
74
|
@script_asset_folder = File.join(settings.asset_folder, 'javascripts')
|
64
75
|
@style_asset_folder = File.join(settings.asset_folder, 'stylesheets')
|
65
|
-
|
66
|
-
@disclaimer = "// This file is automatically generated from the contents\n// in #{settings.pubba_config}\n//\n"
|
67
76
|
end
|
68
77
|
|
69
78
|
def maybe_init_r18n(settings)
|
@@ -90,6 +99,13 @@ module Sinatra
|
|
90
99
|
@asset_handler.asset_paths style_asset_folder, script_asset_folder
|
91
100
|
end
|
92
101
|
|
102
|
+
def configure_asset_compressor(settings)
|
103
|
+
@asset_minifier = Sinatra::Pubba::Assets::YUIMinifier
|
104
|
+
if settings.respond_to?(:asset_minifier) && (minifier = settings.asset_minifier)
|
105
|
+
@asset_minifier = minifier
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
93
109
|
def page(name)
|
94
110
|
pages[name]
|
95
111
|
end
|
@@ -99,7 +115,7 @@ module Sinatra
|
|
99
115
|
end
|
100
116
|
|
101
117
|
def add_page(name, hsh)
|
102
|
-
p = Page.new(name, @
|
118
|
+
p = Page.new(name, @asset_configuration.global_config!)
|
103
119
|
|
104
120
|
p.add_asset('styles', hsh['styles']) if hsh['styles']
|
105
121
|
p.add_asset('scripts', hsh['scripts']) if hsh['scripts']
|
@@ -120,6 +136,11 @@ module Sinatra
|
|
120
136
|
asset.save_as "#{to_folder}/#{File.basename(file)}"
|
121
137
|
end
|
122
138
|
end
|
139
|
+
|
140
|
+
def minify_assets(app)
|
141
|
+
asset_minifier.minify(script_public_folder, :js)
|
142
|
+
asset_minifier.minify(style_public_folder, :css)
|
143
|
+
end
|
123
144
|
end # Site
|
124
145
|
end # Pubba
|
125
146
|
end # Sinatra
|
data/pubba.gemspec
CHANGED
@@ -20,7 +20,8 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
|
22
22
|
s.add_runtime_dependency('sprockets', ['~> 2.1.2'])
|
23
|
-
s.add_runtime_dependency('r18n-desktop', ['~> 0.4.
|
23
|
+
s.add_runtime_dependency('r18n-desktop', ['~> 0.4.13'])
|
24
|
+
s.add_runtime_dependency('yui-compressor', ['>= 0.9.4'])
|
24
25
|
|
25
26
|
s.add_development_dependency('rake', ['>= 0.9.2'])
|
26
27
|
s.add_development_dependency('sinatra', ['>= 1.3.1'])
|
data/test/helper.rb
CHANGED
@@ -42,6 +42,10 @@ class TestPubba < MiniTest::Unit::TestCase
|
|
42
42
|
|
43
43
|
register Sinatra::Pubba
|
44
44
|
|
45
|
+
get('/') do
|
46
|
+
'OK'
|
47
|
+
end
|
48
|
+
|
45
49
|
get('/home-page-head-tags') do
|
46
50
|
@page = Sinatra::Pubba::Site.page('home');
|
47
51
|
page_head_tags
|
@@ -52,18 +56,8 @@ class TestPubba < MiniTest::Unit::TestCase
|
|
52
56
|
page_body_tags
|
53
57
|
end
|
54
58
|
end
|
55
|
-
end
|
56
59
|
|
57
|
-
|
58
|
-
[R.asset_folder, R.public_folder].each do |root_folder|
|
59
|
-
Dir.glob(File.join(root_folder, 'javascripts', '*.js')) do |f|
|
60
|
-
File.delete(f) if File.exist?(f)
|
61
|
-
end
|
62
|
-
|
63
|
-
Dir.glob(File.join(root_folder, 'stylesheets', '*.css')) do |f|
|
64
|
-
File.delete(f) if File.exist?(f)
|
65
|
-
end
|
66
|
-
end
|
60
|
+
get '/'
|
67
61
|
end
|
68
62
|
|
69
63
|
def empty_hash
|
data/test/pubba/test_page.rb
CHANGED
@@ -19,7 +19,7 @@ class TestPubbaPage < TestPubba
|
|
19
19
|
css = File.open( File.join(R.asset_folder, 'stylesheets', 'home-all.css')){|f| f.read }
|
20
20
|
contents = <<TEXT
|
21
21
|
// This file is automatically generated from the contents
|
22
|
-
// in #{
|
22
|
+
// in #{Sinatra::Pubba::Site.asset_configuration.name}
|
23
23
|
//
|
24
24
|
//= require custom/global.css
|
25
25
|
//= require custom/home.css
|
@@ -32,7 +32,7 @@ TEXT
|
|
32
32
|
css = File.open( File.join(R.asset_folder, 'stylesheets', 'home-phone.css')){|f| f.read }
|
33
33
|
contents = <<TEXT
|
34
34
|
// This file is automatically generated from the contents
|
35
|
-
// in #{
|
35
|
+
// in #{Sinatra::Pubba::Site.asset_configuration.name}
|
36
36
|
//
|
37
37
|
//= require custom/small.css
|
38
38
|
TEXT
|
@@ -44,7 +44,7 @@ TEXT
|
|
44
44
|
css = File.open( File.join(R.asset_folder, 'stylesheets', 'home-desktop.css')){|f| f.read }
|
45
45
|
contents = <<TEXT
|
46
46
|
// This file is automatically generated from the contents
|
47
|
-
// in #{
|
47
|
+
// in #{Sinatra::Pubba::Site.asset_configuration.name}
|
48
48
|
//
|
49
49
|
//= require custom/large.css
|
50
50
|
TEXT
|
@@ -56,7 +56,7 @@ TEXT
|
|
56
56
|
css = File.open( File.join(R.asset_folder, 'stylesheets', 'search-all.css')){|f| f.read }
|
57
57
|
contents = <<TEXT
|
58
58
|
// This file is automatically generated from the contents
|
59
|
-
// in #{
|
59
|
+
// in #{Sinatra::Pubba::Site.asset_configuration.name}
|
60
60
|
//
|
61
61
|
//= require custom/global.css
|
62
62
|
//= require custom/search.css
|
@@ -70,7 +70,7 @@ TEXT
|
|
70
70
|
css = File.open( File.join(R.asset_folder, 'stylesheets', 'search-phone.css')){|f| f.read }
|
71
71
|
contents = <<TEXT
|
72
72
|
// This file is automatically generated from the contents
|
73
|
-
// in #{
|
73
|
+
// in #{Sinatra::Pubba::Site.asset_configuration.name}
|
74
74
|
//
|
75
75
|
//= require custom/small.css
|
76
76
|
TEXT
|
@@ -82,7 +82,7 @@ TEXT
|
|
82
82
|
css = File.open( File.join(R.asset_folder, 'stylesheets', 'search-desktop.css')){|f| f.read }
|
83
83
|
contents = <<TEXT
|
84
84
|
// This file is automatically generated from the contents
|
85
|
-
// in #{
|
85
|
+
// in #{Sinatra::Pubba::Site.asset_configuration.name}
|
86
86
|
//
|
87
87
|
//= require custom/large.css
|
88
88
|
TEXT
|
@@ -94,7 +94,7 @@ TEXT
|
|
94
94
|
js = File.open( File.join(R.asset_folder, 'javascripts', 'home-head.js')){|f| f.read }
|
95
95
|
contents = <<TEXT
|
96
96
|
// This file is automatically generated from the contents
|
97
|
-
// in #{
|
97
|
+
// in #{Sinatra::Pubba::Site.asset_configuration.name}
|
98
98
|
//
|
99
99
|
//= require third-party/modernizr.js
|
100
100
|
TEXT
|
@@ -106,7 +106,7 @@ TEXT
|
|
106
106
|
js = File.open( File.join(R.asset_folder, 'javascripts', 'home-body.js')){|f| f.read }
|
107
107
|
contents = <<TEXT
|
108
108
|
// This file is automatically generated from the contents
|
109
|
-
// in #{
|
109
|
+
// in #{Sinatra::Pubba::Site.asset_configuration.name}
|
110
110
|
//
|
111
111
|
//= require third-party/backbone.js
|
112
112
|
//= require custom/app.js
|
@@ -120,7 +120,7 @@ TEXT
|
|
120
120
|
js = File.open( File.join(R.asset_folder, 'javascripts', 'search-head.js')){|f| f.read }
|
121
121
|
contents = <<TEXT
|
122
122
|
// This file is automatically generated from the contents
|
123
|
-
// in #{
|
123
|
+
// in #{Sinatra::Pubba::Site.asset_configuration.name}
|
124
124
|
//
|
125
125
|
//= require third-party/modernizr.js
|
126
126
|
TEXT
|
@@ -132,7 +132,7 @@ TEXT
|
|
132
132
|
js = File.open( File.join(R.asset_folder, 'javascripts', 'search-body.js')){|f| f.read }
|
133
133
|
contents = <<TEXT
|
134
134
|
// This file is automatically generated from the contents
|
135
|
-
// in #{
|
135
|
+
// in #{Sinatra::Pubba::Site.asset_configuration.name}
|
136
136
|
//
|
137
137
|
//= require third-party/backbone.js
|
138
138
|
//= require custom/app.js
|
data/test/pubba/test_site.rb
CHANGED
@@ -5,6 +5,10 @@ class TestPubbaSite < TestPubba
|
|
5
5
|
assert_equal Sinatra::Pubba::Assets::SprocketsHandler, Sinatra::Pubba::Site.asset_handler
|
6
6
|
end
|
7
7
|
|
8
|
+
def test_asset_handler_initialization
|
9
|
+
assert_equal Sinatra::Pubba::Assets::YUIMinifier, Sinatra::Pubba::Site.asset_minifier
|
10
|
+
end
|
11
|
+
|
8
12
|
def test_script_public_folder_initialization
|
9
13
|
assert_equal "#{R.public_folder}/javascripts", Sinatra::Pubba::Site.script_public_folder
|
10
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pubba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sprockets
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152383640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,21 +21,32 @@ dependencies:
|
|
21
21
|
version: 2.1.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152383640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: r18n-desktop
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152382760 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.4.
|
32
|
+
version: 0.4.13
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152382760
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: yui-compressor
|
38
|
+
requirement: &2152381900 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.9.4
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2152381900
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: rake
|
38
|
-
requirement: &
|
49
|
+
requirement: &2152381020 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: 0.9.2
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *2152381020
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: sinatra
|
49
|
-
requirement: &
|
60
|
+
requirement: &2152380000 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: 1.3.1
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *2152380000
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: sinatra-contrib
|
60
|
-
requirement: &
|
71
|
+
requirement: &2152379420 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ! '>='
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: 1.3.1
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *2152379420
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: yard
|
71
|
-
requirement: &
|
82
|
+
requirement: &2152378680 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,7 +87,7 @@ dependencies:
|
|
76
87
|
version: '0'
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *2152378680
|
80
91
|
description:
|
81
92
|
email:
|
82
93
|
- andy@stonean.com
|
@@ -94,7 +105,9 @@ files:
|
|
94
105
|
- lib/sinatra/pubba.rb
|
95
106
|
- lib/sinatra/pubba/assets/configuration.rb
|
96
107
|
- lib/sinatra/pubba/assets/handler.rb
|
108
|
+
- lib/sinatra/pubba/assets/minifier.rb
|
97
109
|
- lib/sinatra/pubba/assets/sprockets_handler.rb
|
110
|
+
- lib/sinatra/pubba/assets/yui_minifier.rb
|
98
111
|
- lib/sinatra/pubba/errors.rb
|
99
112
|
- lib/sinatra/pubba/html/helpers.rb
|
100
113
|
- lib/sinatra/pubba/locale.rb
|
@@ -105,6 +118,7 @@ files:
|
|
105
118
|
- test/helper.rb
|
106
119
|
- test/pubba/assets/test_configuration.rb
|
107
120
|
- test/pubba/assets/test_handler.rb
|
121
|
+
- test/pubba/assets/test_minifier.rb
|
108
122
|
- test/pubba/html/test_helpers.rb
|
109
123
|
- test/pubba/test_page.rb
|
110
124
|
- test/pubba/test_site.rb
|