pubba 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,97 @@
1
+ require 'statica'
2
+
3
+ require_relative 'assets/configuration'
4
+ require_relative 'assets/sprockets_handler'
5
+ require_relative 'assets/yui_minifier'
6
+ require_relative 'page'
7
+
8
+ module Pubba
9
+ module Site
10
+ extend self
11
+
12
+ attr_reader :asset_configuration, :locale
13
+
14
+ def configure
15
+ Statica.root_dir = Pubba.public_folder
16
+
17
+ maybe_init_r18n
18
+
19
+ # Load pubba_config
20
+ @asset_configuration = Pubba::Assets::Configuration.new(Pubba.config_file)
21
+
22
+ # Set assset handler
23
+ configure_asset_handler
24
+
25
+ # Set pages to empty hash
26
+ @pages = {}
27
+
28
+ # Process the remaining @pubba_config sections
29
+ asset_configuration.process do |p, config|
30
+ add_page(p, config)
31
+ end
32
+ end
33
+
34
+ def process
35
+ pages.each{|name, p| p.assetize }
36
+
37
+ asset_script_folder = File.join(Pubba.asset_folder, 'out', Pubba.script_folder)
38
+ asset_style_folder = File.join(Pubba.asset_folder, 'out', Pubba.style_folder)
39
+
40
+ public_script_folder = File.join(Pubba.public_folder, Pubba.script_folder)
41
+ public_style_folder = File.join(Pubba.public_folder, Pubba.style_folder)
42
+
43
+ Pubba.asset_handler.process(asset_script_folder, public_script_folder)
44
+ Pubba.asset_handler.process(asset_style_folder, public_style_folder)
45
+
46
+ Pubba.asset_minifier.minify(public_script_folder, :js)
47
+ Pubba.asset_minifier.minify(public_style_folder, :css)
48
+ end
49
+
50
+ def asset_host=(p)
51
+ @asset_host = p
52
+ end
53
+
54
+ def asset_host
55
+ @asset_host ||= -> asset {asset}
56
+ end
57
+
58
+ def maybe_init_r18n
59
+ return unless Pubba.r18n_folder
60
+
61
+ locale = 'en'
62
+ locale = Pubba.r18n_locale if Pubba.r18n_locale
63
+
64
+ @r18n_folder = Pubba.r18n_folder
65
+ @r18n_locale = locale
66
+
67
+ require_relative 'locale'
68
+
69
+ @locale = Locale.new
70
+ end
71
+
72
+ def configure_asset_handler
73
+ Pubba.asset_handler.asset_paths Pubba.asset_folder,
74
+ File.join(Pubba.asset_folder, Pubba.style_folder),
75
+ File.join(Pubba.asset_folder, Pubba.script_folder)
76
+ end
77
+
78
+ def page(name)
79
+ pages[name]
80
+ end
81
+
82
+ def pages
83
+ @pages ||= {}
84
+ end
85
+
86
+ def add_page(name, hsh)
87
+ p = Page.new(name, @asset_configuration.global_config!)
88
+
89
+ p.add_asset('styles', hsh['styles']) if hsh['styles']
90
+ p.add_asset('scripts', hsh['scripts']) if hsh['scripts']
91
+
92
+ p.tagify
93
+
94
+ pages[name] = p
95
+ end
96
+ end # Site
97
+ end # Pubba
@@ -1,5 +1,5 @@
1
1
  module Pubba
2
2
  # Pubba version string
3
3
  # @api public
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.0'
5
5
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.dirname(__FILE__) + '/lib/sinatra/pubba/version'
2
+ require File.dirname(__FILE__) + '/lib/pubba/version'
3
3
  require 'date'
4
4
 
5
5
  Gem::Specification.new do |s|
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.date = Date.today.to_s
9
9
  s.authors = ['Andrew Stone']
10
10
  s.email = ['andy@stonean.com']
11
- s.summary = 'Pubba is a Sinatra extension designed to help you manage the static components of your site.'
11
+ s.summary = 'Pubba is a library designed to help you manage the static components of your site.'
12
12
  s.homepage = 'http://github.com/stonean/pubba'
13
13
  s.extra_rdoc_files = %w(README.md)
14
14
  s.rdoc_options = %w(--charset=UTF-8)
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_runtime_dependency('r18n-desktop', ['~> 0.4.13'])
24
24
  s.add_runtime_dependency('yui-compressor', ['>= 0.9.4'])
25
25
  s.add_runtime_dependency('fssm', ['>= 0.2.7'])
26
- s.add_runtime_dependency('statica', ['>= 0.2.0'])
26
+ s.add_runtime_dependency('statica', ['>= 0.3.0'])
27
27
 
28
28
  s.add_development_dependency('rake', ['>= 0.9.2'])
29
29
  s.add_development_dependency('sinatra', ['>= 1.3.1'])
@@ -32,27 +32,32 @@ class TestPubba < MiniTest::Unit::TestCase
32
32
 
33
33
  def setup
34
34
  mock_app do
35
- require 'sinatra/pubba'
35
+ require 'pubba'
36
36
 
37
37
  settings.set :public_folder, R.public_folder
38
- settings.set :asset_folder, R.asset_folder
39
- settings.set :r18n_folder, R.r18n_folder
40
38
 
41
- settings.set :pubba_config, R.pubba_config_file
39
+ Pubba.configure do |p|
40
+ p.config_file = R.pubba_config_file
41
+ p.public_folder = settings.public_folder
42
+ p.asset_folder = R.asset_folder
43
+ p.r18n_folder = R.r18n_folder
44
+ end
45
+
46
+ Pubba::Site.configure
42
47
 
43
- register Sinatra::Pubba
48
+ helpers Pubba::HTML::Helpers
44
49
 
45
50
  get('/') do
46
51
  'OK'
47
52
  end
48
53
 
49
54
  get('/home-page-head-tags') do
50
- @page = Sinatra::Pubba::Site.page('home');
55
+ @page = Pubba::Site.page('home');
51
56
  page_head_tags
52
57
  end
53
58
 
54
59
  get('/home-page-body-tags') do
55
- @page = Sinatra::Pubba::Site.page('home');
60
+ @page = Pubba::Site.page('home');
56
61
  page_body_tags
57
62
  end
58
63
  end
@@ -2,7 +2,7 @@ require 'helper'
2
2
 
3
3
  class TestPubbaAssetsConfiguration < TestPubba
4
4
  def setup
5
- @config = Sinatra::Pubba::Assets::Configuration.new(R.pubba_config_file)
5
+ @config = Pubba::Assets::Configuration.new(R.pubba_config_file)
6
6
  end
7
7
 
8
8
  def test_yaml_is_initialized
@@ -3,26 +3,26 @@ require 'helper'
3
3
  class TestHandler < TestPubba
4
4
  def test_asset
5
5
  assert_raises NotImplementedError do
6
- Sinatra::Pubba::Assets::Handler.asset('')
6
+ Pubba::Assets::Handler.asset('')
7
7
  end
8
8
  end
9
9
 
10
10
  def test_save_as
11
- handler = Sinatra::Pubba::Assets::Handler.new
11
+ handler = Pubba::Assets::Handler.new
12
12
  assert_raises NotImplementedError do
13
13
  handler.save_as('')
14
14
  end
15
15
  end
16
16
 
17
17
  def test_process
18
- handler = Sinatra::Pubba::Assets::Handler.new
18
+ handler = Pubba::Assets::Handler.new
19
19
  assert_raises NotImplementedError do
20
20
  handler.process('', '')
21
21
  end
22
22
  end
23
23
 
24
24
  def test_build
25
- handler = Sinatra::Pubba::Assets::Handler.new
25
+ handler = Pubba::Assets::Handler.new
26
26
  assert_raises NotImplementedError do
27
27
  handler.build('', '', '', '')
28
28
  end
@@ -3,7 +3,7 @@ require 'helper'
3
3
  class TestMinifier < TestPubba
4
4
  def test_minify
5
5
  assert_raises NotImplementedError do
6
- Sinatra::Pubba::Assets::Minifier.minify("/folder/path", :js)
6
+ Pubba::Assets::Minifier.minify("/folder/path", :js)
7
7
  end
8
8
  end
9
9
  end
@@ -1,8 +1,8 @@
1
1
  require 'helper'
2
- require 'sinatra/pubba/html/helpers'
2
+ require 'pubba/html/helpers'
3
3
 
4
4
  class TestPubbaHTMLHelper < TestPubba
5
- include Sinatra::Pubba::HTML::Helpers
5
+ include Pubba::HTML::Helpers
6
6
 
7
7
  def test_home_page_head_tags
8
8
  res = get('/home-page-head-tags').body
@@ -18,4 +18,13 @@ class TestPubbaHTMLHelper < TestPubba
18
18
 
19
19
  assert_match reg, res
20
20
  end
21
+
22
+ def test_home_page_body_tags_with_asset_host
23
+ Pubba::Site.asset_host = -> asset {"http://myasset.mydomain.com#{asset}"}
24
+ res = get('/home-page-body-tags').body
25
+ reg = Regexp.new '<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script><script src="http://myasset.mydomain.com/js/home-body.js/\w+" type="text/javascript"></script>'
26
+
27
+ assert_match reg, res
28
+ Pubba::Site.asset_host = nil
29
+ end
21
30
  end
@@ -2,14 +2,14 @@ require 'helper'
2
2
 
3
3
  class TestPubbaPage < TestPubba
4
4
  def test_home_r18n
5
- page = Sinatra::Pubba::Site.page('home')
5
+ page = Pubba::Site.page('home')
6
6
 
7
7
  assert_equal 'Home title', page.title
8
8
  assert_equal 'Logout', page.logout_link
9
9
  end
10
10
 
11
11
  def test_search_r18n
12
- page = Sinatra::Pubba::Site.page('search')
12
+ page = Pubba::Site.page('search')
13
13
 
14
14
  assert_equal 'Search title', page.title
15
15
  assert_equal 'Logout', page.logout_link
@@ -19,7 +19,7 @@ class TestPubbaPage < TestPubba
19
19
  css = File.open( File.join(R.asset_folder, 'out', 'css', 'home-all.css')){|f| f.read }
20
20
  contents = <<TEXT
21
21
  // This file is automatically generated from the contents
22
- // in #{Sinatra::Pubba::Site.asset_configuration.name}
22
+ // in #{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, 'out', 'css', 'home-phone.css')){|f| f.read }
33
33
  contents = <<TEXT
34
34
  // This file is automatically generated from the contents
35
- // in #{Sinatra::Pubba::Site.asset_configuration.name}
35
+ // in #{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, 'out', 'css', 'home-desktop.css')){|f| f.read }
45
45
  contents = <<TEXT
46
46
  // This file is automatically generated from the contents
47
- // in #{Sinatra::Pubba::Site.asset_configuration.name}
47
+ // in #{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, 'out', 'css', 'search-all.css')){|f| f.read }
57
57
  contents = <<TEXT
58
58
  // This file is automatically generated from the contents
59
- // in #{Sinatra::Pubba::Site.asset_configuration.name}
59
+ // in #{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, 'out', 'css', 'search-phone.css')){|f| f.read }
71
71
  contents = <<TEXT
72
72
  // This file is automatically generated from the contents
73
- // in #{Sinatra::Pubba::Site.asset_configuration.name}
73
+ // in #{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, 'out', 'css', 'search-desktop.css')){|f| f.read }
83
83
  contents = <<TEXT
84
84
  // This file is automatically generated from the contents
85
- // in #{Sinatra::Pubba::Site.asset_configuration.name}
85
+ // in #{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, 'out', 'js', 'home-head.js')){|f| f.read }
95
95
  contents = <<TEXT
96
96
  // This file is automatically generated from the contents
97
- // in #{Sinatra::Pubba::Site.asset_configuration.name}
97
+ // in #{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, 'out', 'js', 'home-body.js')){|f| f.read }
107
107
  contents = <<TEXT
108
108
  // This file is automatically generated from the contents
109
- // in #{Sinatra::Pubba::Site.asset_configuration.name}
109
+ // in #{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, 'out', 'js', 'search-head.js')){|f| f.read }
121
121
  contents = <<TEXT
122
122
  // This file is automatically generated from the contents
123
- // in #{Sinatra::Pubba::Site.asset_configuration.name}
123
+ // in #{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, 'out', 'js', 'search-body.js')){|f| f.read }
133
133
  contents = <<TEXT
134
134
  // This file is automatically generated from the contents
135
- // in #{Sinatra::Pubba::Site.asset_configuration.name}
135
+ // in #{Pubba::Site.asset_configuration.name}
136
136
  //
137
137
  //= require third-party/backbone.js
138
138
  //= require custom/app.js
@@ -2,26 +2,26 @@ require 'helper'
2
2
 
3
3
  class TestPubbaSite < TestPubba
4
4
  def test_asset_handler_initialization
5
- assert_equal Sinatra::Pubba::Assets::SprocketsHandler, Sinatra::Pubba::Site.asset_handler
5
+ assert_equal Pubba::Assets::SprocketsHandler, Pubba.asset_handler
6
6
  end
7
7
 
8
8
  def test_asset_handler_initialization
9
- assert_equal Sinatra::Pubba::Assets::YUIMinifier, Sinatra::Pubba::Site.asset_minifier
9
+ assert_equal Pubba::Assets::YUIMinifier, Pubba.asset_minifier
10
10
  end
11
11
 
12
12
  def test_asset_folder_initialization
13
- assert_equal "#{R.asset_folder}", Sinatra::Pubba::Site.asset_folder
13
+ assert_equal "#{R.asset_folder}", Pubba.asset_folder
14
14
  end
15
15
 
16
16
  def test_public_folder_initialization
17
- assert_equal "#{R.public_folder}", Sinatra::Pubba::Site.public_folder
17
+ assert_equal "#{R.public_folder}", Pubba.public_folder
18
18
  end
19
19
 
20
20
  def test_script_folder_initialization
21
- assert_equal "js", Sinatra::Pubba::Site.script_folder
21
+ assert_equal "js", Pubba.script_folder
22
22
  end
23
23
 
24
24
  def test_style_folder_initialization
25
- assert_equal "css", Sinatra::Pubba::Site.style_folder
25
+ assert_equal "css", Pubba.style_folder
26
26
  end
27
27
  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.6.0
4
+ version: 0.7.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-22 00:00:00.000000000 Z
12
+ date: 2011-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets
16
- requirement: &2151888640 !ruby/object:Gem::Requirement
16
+ requirement: &2151888720 !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: *2151888640
24
+ version_requirements: *2151888720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: r18n-desktop
27
- requirement: &2151887220 !ruby/object:Gem::Requirement
27
+ requirement: &2151887340 !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: *2151887220
35
+ version_requirements: *2151887340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: yui-compressor
38
- requirement: &2151902720 !ruby/object:Gem::Requirement
38
+ requirement: &2151902760 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.9.4
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2151902720
46
+ version_requirements: *2151902760
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: fssm
49
- requirement: &2151901700 !ruby/object:Gem::Requirement
49
+ requirement: &2151901780 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,21 +54,21 @@ dependencies:
54
54
  version: 0.2.7
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2151901700
57
+ version_requirements: *2151901780
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: statica
60
- requirement: &2151900860 !ruby/object:Gem::Requirement
60
+ requirement: &2151901000 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
64
64
  - !ruby/object:Gem::Version
65
- version: 0.2.0
65
+ version: 0.3.0
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2151900860
68
+ version_requirements: *2151901000
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
- requirement: &2151900020 !ruby/object:Gem::Requirement
71
+ requirement: &2151900060 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.9.2
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2151900020
79
+ version_requirements: *2151900060
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: sinatra
82
- requirement: &2151899180 !ruby/object:Gem::Requirement
82
+ requirement: &2151899220 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.3.1
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2151899180
90
+ version_requirements: *2151899220
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: sinatra-contrib
93
- requirement: &2151898320 !ruby/object:Gem::Requirement
93
+ requirement: &2151898380 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 1.3.1
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2151898320
101
+ version_requirements: *2151898380
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: yard
104
- requirement: &2151897500 !ruby/object:Gem::Requirement
104
+ requirement: &2151897560 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2151897500
112
+ version_requirements: *2151897560
113
113
  description:
114
114
  email:
115
115
  - andy@stonean.com
@@ -124,19 +124,19 @@ files:
124
124
  - Gemfile
125
125
  - README.md
126
126
  - Rakefile
127
- - lib/sinatra/pubba.rb
128
- - lib/sinatra/pubba/assets/configuration.rb
129
- - lib/sinatra/pubba/assets/handler.rb
130
- - lib/sinatra/pubba/assets/minifier.rb
131
- - lib/sinatra/pubba/assets/sprockets_handler.rb
132
- - lib/sinatra/pubba/assets/yui_minifier.rb
133
- - lib/sinatra/pubba/errors.rb
134
- - lib/sinatra/pubba/html/helpers.rb
135
- - lib/sinatra/pubba/locale.rb
136
- - lib/sinatra/pubba/monitor.rb
137
- - lib/sinatra/pubba/page.rb
138
- - lib/sinatra/pubba/site.rb
139
- - lib/sinatra/pubba/version.rb
127
+ - lib/pubba.rb
128
+ - lib/pubba/assets/configuration.rb
129
+ - lib/pubba/assets/handler.rb
130
+ - lib/pubba/assets/minifier.rb
131
+ - lib/pubba/assets/sprockets_handler.rb
132
+ - lib/pubba/assets/yui_minifier.rb
133
+ - lib/pubba/errors.rb
134
+ - lib/pubba/html/helpers.rb
135
+ - lib/pubba/locale.rb
136
+ - lib/pubba/monitor.rb
137
+ - lib/pubba/page.rb
138
+ - lib/pubba/site.rb
139
+ - lib/pubba/version.rb
140
140
  - pubba.gemspec
141
141
  - test/helper.rb
142
142
  - test/pubba/assets/test_configuration.rb
@@ -182,7 +182,7 @@ rubyforge_project: pubba
182
182
  rubygems_version: 1.8.10
183
183
  signing_key:
184
184
  specification_version: 3
185
- summary: Pubba is a Sinatra extension designed to help you manage the static components
186
- of your site.
185
+ summary: Pubba is a library designed to help you manage the static components of your
186
+ site.
187
187
  test_files: []
188
188
  has_rdoc: