pubba 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +5 -0
- data/lib/sinatra/pubba.rb +0 -6
- data/lib/sinatra/pubba/assets/configuration.rb +3 -3
- data/lib/sinatra/pubba/monitor.rb +24 -0
- data/lib/sinatra/pubba/page.rb +54 -24
- data/lib/sinatra/pubba/site.rb +24 -15
- data/lib/sinatra/pubba/version.rb +1 -1
- data/pubba.gemspec +1 -0
- metadata +28 -16
data/CHANGES
CHANGED
data/lib/sinatra/pubba.rb
CHANGED
@@ -4,12 +4,12 @@ module Sinatra
|
|
4
4
|
module Pubba
|
5
5
|
module Assets
|
6
6
|
class Configuration
|
7
|
-
attr_reader :yaml
|
8
|
-
attr_reader :name
|
7
|
+
attr_reader :yaml, :name, :disclaimer
|
9
8
|
|
10
9
|
def initialize(config_file)
|
11
|
-
@name = File.basename(config_file)
|
12
10
|
@yaml = Psych.load_file(config_file)
|
11
|
+
@name = File.basename(config_file)
|
12
|
+
@disclaimer = "// This file is automatically generated from the contents\n// in #{name}\n//\n"
|
13
13
|
end
|
14
14
|
|
15
15
|
def global_config!
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'fssm'
|
2
|
+
|
3
|
+
module Sinatra
|
4
|
+
module Pubba
|
5
|
+
module Monitor
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def do
|
9
|
+
start_monitor unless @running
|
10
|
+
end
|
11
|
+
|
12
|
+
def start_monitor
|
13
|
+
@running = Thread.new do
|
14
|
+
puts "Pubba is now monitoring: #{Site.asset_folder}"
|
15
|
+
FSSM.monitor(Site.asset_folder, '**/*', :directories => true) do
|
16
|
+
update {|base, relative, type| Site.process}
|
17
|
+
delete {|base, relative, type| Site.process}
|
18
|
+
create {|base, relative, type| Site.process}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end # Monitor
|
23
|
+
end # Pubba
|
24
|
+
end # Sinatra
|
data/lib/sinatra/pubba/page.rb
CHANGED
@@ -14,14 +14,15 @@ module Sinatra
|
|
14
14
|
@assets["styles"][key] = value.dup
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
script_groups do |group|
|
18
|
+
@assets["scripts"][group] = global_configuration["scripts"][group] || []
|
19
|
+
end
|
19
20
|
end
|
20
21
|
|
21
22
|
def add_asset(type, section)
|
22
23
|
if type == "styles"
|
23
|
-
section.each do |section_name,
|
24
|
-
|
24
|
+
section.each do |section_name, hash|
|
25
|
+
hash.each do |key, value|
|
25
26
|
if key == "urls"
|
26
27
|
@assets[type][section_name][key] += value
|
27
28
|
else
|
@@ -30,8 +31,9 @@ module Sinatra
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
else
|
33
|
-
|
34
|
-
|
34
|
+
script_groups do |group|
|
35
|
+
@assets["scripts"][group] += section[group] if section[group]
|
36
|
+
end
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
@@ -40,6 +42,20 @@ module Sinatra
|
|
40
42
|
create_script_assets
|
41
43
|
end
|
42
44
|
|
45
|
+
def tagify
|
46
|
+
style_groups do |group, hash|
|
47
|
+
style_urls(group) do |url|
|
48
|
+
add_style_tag(group, hash, url)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
script_groups do |group|
|
53
|
+
script_urls(group) do |url|
|
54
|
+
add_script_tag(group, url)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
43
59
|
def method_missing(meth, *args)
|
44
60
|
if Site.locale && (t = Site.locale.get(name, meth, *args))
|
45
61
|
return t
|
@@ -56,55 +72,69 @@ module Sinatra
|
|
56
72
|
end
|
57
73
|
|
58
74
|
def create_style_assets
|
59
|
-
|
75
|
+
style_groups do |group, hash|
|
60
76
|
content = []
|
61
|
-
|
62
|
-
add_style_tag(part, hsh, url)
|
77
|
+
style_urls(group) do |url|
|
63
78
|
next if url.start_with?("http")
|
64
79
|
content << "//= require #{url}.css"
|
65
80
|
end
|
66
|
-
write_asset(Site.style_asset_folder,
|
81
|
+
write_asset(Site.style_asset_folder, group, "css", content.compact.join("\n"))
|
67
82
|
end
|
68
83
|
end
|
69
84
|
|
70
85
|
def create_script_assets
|
71
|
-
|
86
|
+
script_groups do |group|
|
72
87
|
content = []
|
73
|
-
|
74
|
-
add_script_tag(part, url)
|
88
|
+
script_urls(group) do |url|
|
75
89
|
next if url.start_with?("http")
|
76
90
|
content << "//= require #{url}.js"
|
77
91
|
end
|
78
|
-
write_asset(Site.script_asset_folder,
|
92
|
+
write_asset(Site.script_asset_folder, group, "js", content.compact.join("\n"))
|
79
93
|
end
|
80
94
|
end
|
81
95
|
|
82
|
-
def
|
96
|
+
def style_groups
|
97
|
+
@assets["styles"].each{|group, hash| yield group, hash }
|
98
|
+
end
|
99
|
+
|
100
|
+
def style_urls(group)
|
101
|
+
@assets["styles"][group]["urls"].each{|url| yield url }
|
102
|
+
end
|
103
|
+
|
104
|
+
def script_groups
|
105
|
+
["head", "body"].each{|group| yield group }
|
106
|
+
end
|
107
|
+
|
108
|
+
def script_urls(group)
|
109
|
+
@assets["scripts"][group].each{|url| yield url }
|
110
|
+
end
|
111
|
+
|
112
|
+
def add_style_tag(group, hash, url)
|
83
113
|
h = { tag: 'link', type: 'text/css', rel: 'stylesheet' }
|
84
|
-
h[:media] =
|
85
|
-
h[:href] = url.start_with?("http") ? url : "/stylesheets/#{name}-#{
|
114
|
+
h[:media] = hash['media'] if hash['media']
|
115
|
+
h[:href] = url.start_with?("http") ? url : "/stylesheets/#{name}-#{group}.css"
|
86
116
|
|
87
117
|
maybe_add_tag(@head_tags, h, :href)
|
88
118
|
end
|
89
119
|
|
90
|
-
def add_script_tag(
|
120
|
+
def add_script_tag(group, url)
|
91
121
|
h = { tag: 'script', type: "text/javascript" }
|
92
|
-
h[:src] = url.start_with?("http") ? url : "/javascripts/#{name}-#{
|
122
|
+
h[:src] = url.start_with?("http") ? url : "/javascripts/#{name}-#{group}.js"
|
93
123
|
|
94
|
-
tag_set = (
|
124
|
+
tag_set = (group == "head") ? @head_tags : @body_tags
|
95
125
|
maybe_add_tag(tag_set, h, :src)
|
96
126
|
end
|
97
127
|
|
98
|
-
def maybe_add_tag(tag_set,
|
128
|
+
def maybe_add_tag(tag_set, hash, key)
|
99
129
|
found = false
|
100
|
-
tag_set.each{|tag| found = true if tag[key] ==
|
101
|
-
tag_set <<
|
130
|
+
tag_set.each{|tag| found = true if tag[key] == hash[key]}
|
131
|
+
tag_set << hash unless found
|
102
132
|
end
|
103
133
|
|
104
134
|
def write_asset(dir, type, ext, content)
|
105
135
|
fname = File.join(dir, "#{name}-#{type}.#{ext}")
|
106
136
|
File.open(fname, 'w') do |f|
|
107
|
-
f.write Site.disclaimer
|
137
|
+
f.write Site.asset_configuration.disclaimer
|
108
138
|
f.write content
|
109
139
|
end
|
110
140
|
end
|
data/lib/sinatra/pubba/site.rb
CHANGED
@@ -7,14 +7,19 @@ module Sinatra
|
|
7
7
|
module Pubba
|
8
8
|
module Site
|
9
9
|
extend self
|
10
|
+
attr_reader :asset_folder
|
10
11
|
attr_reader :script_asset_folder, :style_asset_folder
|
11
12
|
attr_reader :script_public_folder, :style_public_folder
|
12
13
|
|
13
14
|
attr_reader :asset_configuration, :asset_handler, :asset_minifier
|
14
|
-
attr_reader :
|
15
|
+
attr_reader :locale, :r18n_folder, :r18n_locale
|
15
16
|
|
16
17
|
|
17
18
|
def configure(app)
|
19
|
+
return if @configured
|
20
|
+
|
21
|
+
puts "Configuring Pubba..."
|
22
|
+
|
18
23
|
settings = app.settings
|
19
24
|
|
20
25
|
validate_settings(settings)
|
@@ -26,8 +31,6 @@ module Sinatra
|
|
26
31
|
# Load pubba_config
|
27
32
|
@asset_configuration = Sinatra::Pubba::Assets::Configuration.new(settings.pubba_config)
|
28
33
|
|
29
|
-
@disclaimer = "// This file is automatically generated from the contents\n// in #{@asset_configuration.name}\n//\n"
|
30
|
-
|
31
34
|
# Set assset handler
|
32
35
|
configure_asset_handler(settings)
|
33
36
|
|
@@ -38,19 +41,22 @@ module Sinatra
|
|
38
41
|
asset_configuration.process do |p, config|
|
39
42
|
add_page(p, config)
|
40
43
|
end
|
41
|
-
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
p.assetize
|
46
|
-
end
|
45
|
+
if app.settings.development? || app.settings.test?
|
46
|
+
process
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
require_relative 'monitor'
|
49
|
+
Monitor.do
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
+
@configured = true
|
52
53
|
end
|
53
54
|
|
55
|
+
def process
|
56
|
+
pages.each{|name, p| p.assetize }
|
57
|
+
compile_assets
|
58
|
+
minify_assets
|
59
|
+
end
|
54
60
|
|
55
61
|
def validate_settings(settings)
|
56
62
|
missing_settings = []
|
@@ -71,8 +77,9 @@ module Sinatra
|
|
71
77
|
def set_folder_defaults(settings)
|
72
78
|
@script_public_folder = File.join(settings.public_folder, 'javascripts')
|
73
79
|
@style_public_folder = File.join(settings.public_folder, 'stylesheets')
|
74
|
-
@
|
75
|
-
@
|
80
|
+
@asset_folder = settings.asset_folder
|
81
|
+
@script_asset_folder = File.join(@asset_folder, 'javascripts')
|
82
|
+
@style_asset_folder = File.join(@asset_folder, 'stylesheets')
|
76
83
|
end
|
77
84
|
|
78
85
|
def maybe_init_r18n(settings)
|
@@ -120,12 +127,14 @@ module Sinatra
|
|
120
127
|
p.add_asset('styles', hsh['styles']) if hsh['styles']
|
121
128
|
p.add_asset('scripts', hsh['scripts']) if hsh['scripts']
|
122
129
|
|
130
|
+
p.tagify
|
131
|
+
|
123
132
|
pages[name] = p
|
124
133
|
end
|
125
134
|
|
126
135
|
private
|
127
136
|
|
128
|
-
def compile_assets
|
137
|
+
def compile_assets
|
129
138
|
process_assets(script_asset_folder, script_public_folder)
|
130
139
|
process_assets(style_asset_folder, style_public_folder)
|
131
140
|
end
|
@@ -137,7 +146,7 @@ module Sinatra
|
|
137
146
|
end
|
138
147
|
end
|
139
148
|
|
140
|
-
def minify_assets
|
149
|
+
def minify_assets
|
141
150
|
asset_minifier.minify(script_public_folder, :js)
|
142
151
|
asset_minifier.minify(style_public_folder, :css)
|
143
152
|
end
|
data/pubba.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_runtime_dependency('sprockets', ['~> 2.1.2'])
|
23
23
|
s.add_runtime_dependency('r18n-desktop', ['~> 0.4.13'])
|
24
24
|
s.add_runtime_dependency('yui-compressor', ['>= 0.9.4'])
|
25
|
+
s.add_runtime_dependency('fssm', ['>= 0.2.7'])
|
25
26
|
|
26
27
|
s.add_development_dependency('rake', ['>= 0.9.2'])
|
27
28
|
s.add_development_dependency('sinatra', ['>= 1.3.1'])
|
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.4.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-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sprockets
|
16
|
-
requirement: &
|
16
|
+
requirement: &2151925720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.1.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2151925720
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: r18n-desktop
|
27
|
-
requirement: &
|
27
|
+
requirement: &2151913100 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.4.13
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2151913100
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: yui-compressor
|
38
|
-
requirement: &
|
38
|
+
requirement: &2151918540 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,21 @@ dependencies:
|
|
43
43
|
version: 0.9.4
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2151918540
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: fssm
|
49
|
+
requirement: &2151911280 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.7
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2151911280
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: rake
|
49
|
-
requirement: &
|
60
|
+
requirement: &2151799920 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: 0.9.2
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *2151799920
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: sinatra
|
60
|
-
requirement: &
|
71
|
+
requirement: &2151804560 !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: *2151804560
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: sinatra-contrib
|
71
|
-
requirement: &
|
82
|
+
requirement: &2151803660 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,10 +87,10 @@ dependencies:
|
|
76
87
|
version: 1.3.1
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *2151803660
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: yard
|
82
|
-
requirement: &
|
93
|
+
requirement: &2151802660 !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
95
|
requirements:
|
85
96
|
- - ! '>='
|
@@ -87,7 +98,7 @@ dependencies:
|
|
87
98
|
version: '0'
|
88
99
|
type: :development
|
89
100
|
prerelease: false
|
90
|
-
version_requirements: *
|
101
|
+
version_requirements: *2151802660
|
91
102
|
description:
|
92
103
|
email:
|
93
104
|
- andy@stonean.com
|
@@ -111,6 +122,7 @@ files:
|
|
111
122
|
- lib/sinatra/pubba/errors.rb
|
112
123
|
- lib/sinatra/pubba/html/helpers.rb
|
113
124
|
- lib/sinatra/pubba/locale.rb
|
125
|
+
- lib/sinatra/pubba/monitor.rb
|
114
126
|
- lib/sinatra/pubba/page.rb
|
115
127
|
- lib/sinatra/pubba/site.rb
|
116
128
|
- lib/sinatra/pubba/version.rb
|