theme_park 0.1.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.md +105 -0
- data/Rakefile +16 -0
- data/lib/generators/templates/application.css +5 -0
- data/lib/generators/templates/application.js +3 -0
- data/lib/generators/templates/layouts/application.html.erb +14 -0
- data/lib/generators/templates/theme_park.rb +31 -0
- data/lib/generators/theme_park/create_generator.rb +28 -0
- data/lib/generators/theme_park/install_generator.rb +16 -0
- data/lib/tasks/theme_park.rake +33 -0
- data/lib/theme_park.rb +123 -0
- data/lib/theme_park/configuration.rb +47 -0
- data/lib/theme_park/rails/action_controller.rb +53 -0
- data/lib/theme_park/rails/asset_tag_helper.rb +78 -0
- data/lib/theme_park/rails/server.rb +38 -0
- data/lib/theme_park/railtie.rb +52 -0
- data/lib/theme_park/server.rb +25 -0
- data/lib/theme_park/version.rb +11 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/test1/index.html.erb +1 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +56 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +1703 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/themes/default/assets/javascripts/default.js +0 -0
- data/test/dummy/themes/default/assets/stylesheets/default.css +0 -0
- data/test/dummy/themes/default/views/layouts/application.html.erb +1 -0
- data/test/dummy/themes/default/views/test/edit.html.erb +1 -0
- data/test/dummy/themes/default/views/test/index.html.erb +1 -0
- data/test/dummy/themes/default/views/test/show.html.erb +1 -0
- data/test/dummy/themes/default/views/test1/show.html.erb +1 -0
- data/test/dummy/themes/default1/views/layouts/application.html.erb +1 -0
- data/test/dummy/themes/default1/views/test/edit.html.erb +1 -0
- data/test/dummy/themes/default1/views/test/index.html.erb +1 -0
- data/test/dummy/themes/default1/views/test/show.html.erb +1 -0
- data/test/dummy/themes/default1/views/test1/edit.html.erb +1 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/helper.rb +28 -0
- data/test/rails/action_controller_test.rb +58 -0
- data/test/rails/action_view_test.rb +103 -0
- data/test/rails/server_test.rb +5 -0
- data/test/railtie_test.rb +32 -0
- data/test/server_test.rb +5 -0
- data/test/theme_park_test.rb +79 -0
- data/test/themes/default/test.js +0 -0
- data/test/themes/default1/test1.js +0 -0
- metadata +306 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
</div>
|
24
|
+
</body>
|
25
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
@@ -0,0 +1 @@
|
|
1
|
+
default/test/edit.html.erb
|
@@ -0,0 +1 @@
|
|
1
|
+
default/test/index.html.erb
|
@@ -0,0 +1 @@
|
|
1
|
+
default/test/show.html.erb
|
@@ -0,0 +1 @@
|
|
1
|
+
default/test1/show.html.erb
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
@@ -0,0 +1 @@
|
|
1
|
+
default1/test/edit.html.erb
|
@@ -0,0 +1 @@
|
|
1
|
+
default1/test/index.html.erb
|
@@ -0,0 +1 @@
|
|
1
|
+
default1/test/show.html.erb
|
@@ -0,0 +1 @@
|
|
1
|
+
default1/test1/edit.html.erb
|
Binary file
|
Binary file
|
Binary file
|
data/test/helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler'
|
6
|
+
|
7
|
+
begin
|
8
|
+
Bundler.setup(:default, :development)
|
9
|
+
rescue Bundler::BundlerError => e
|
10
|
+
$stderr.puts e.message
|
11
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
12
|
+
exit e.status_code
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'test/unit'
|
16
|
+
require 'minitest/autorun'
|
17
|
+
|
18
|
+
# Enable turn if it is available
|
19
|
+
begin
|
20
|
+
require 'turn'
|
21
|
+
rescue LoadError
|
22
|
+
end
|
23
|
+
|
24
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
25
|
+
require "rails/test_help"
|
26
|
+
|
27
|
+
Rails.backtrace_cleaner.remove_silencers!
|
28
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestController < ApplicationController
|
4
|
+
theme 'default'
|
5
|
+
|
6
|
+
def index
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
class Test1Controller < ApplicationController
|
12
|
+
theme 'default', :only => :show
|
13
|
+
|
14
|
+
def index
|
15
|
+
end
|
16
|
+
|
17
|
+
def show
|
18
|
+
end
|
19
|
+
|
20
|
+
def edit
|
21
|
+
theme 'default1'
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
class TestControllerTest < ActionController::TestCase
|
27
|
+
|
28
|
+
tests TestController
|
29
|
+
|
30
|
+
def test_class_method_theme_without_options
|
31
|
+
get :index
|
32
|
+
assert @response.body.include?('default/test/index.html.erb')
|
33
|
+
assert_equal 'default', assigns('current_theme')
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
class Test1ControllerTest < ActionController::TestCase
|
39
|
+
|
40
|
+
tests Test1Controller
|
41
|
+
|
42
|
+
def test_class_method_theme_with_options
|
43
|
+
get :index
|
44
|
+
assert @response.body.include?('origin/test1/index.html.erb')
|
45
|
+
assert_equal nil, assigns('current_theme')
|
46
|
+
|
47
|
+
get :show
|
48
|
+
assert @response.body.include?('default/test1/show.html.erb')
|
49
|
+
assert_equal 'default', assigns('current_theme')
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_instance_method_theme
|
53
|
+
get :edit
|
54
|
+
assert @response.body.include?('default1/test1/edit.html.erb')
|
55
|
+
assert_equal 'default1', assigns('current_theme')
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'theme_park/rails/asset_tag_helper'
|
3
|
+
|
4
|
+
class ActionViewTest < ActionView::TestCase
|
5
|
+
tests ThemePark::Rails::AssetTagHelper
|
6
|
+
|
7
|
+
def setup
|
8
|
+
super
|
9
|
+
@current_theme = 'foo'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_theme_stylesheet_link_tag
|
13
|
+
assert_dom_equal '<link href="/stylesheets/xx.css" type="text/css" media="screen" rel="stylesheet"/>', theme_stylesheet_link_tag('xx')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_theme_javascript_include_tag
|
17
|
+
assert_dom_equal '<script src="/javascripts/xx.js" type="text/javascript"></script>', theme_javascript_include_tag('xx')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_theme_image_tag
|
21
|
+
assert_dom_equal '<img alt="Xx" src="/images/xx.jpg" />', theme_image_tag('xx.jpg')
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_theme_compiled_path
|
25
|
+
assert_equal "/themes/foo/bar.js", theme_compiled_path('bar.js')
|
26
|
+
assert_equal "/themes/foo1/bar.js", theme_compiled_path('bar.js', 'foo1')
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_assets_enabled?
|
30
|
+
assert_equal true, assets_enabled?
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_serve_static_assets?
|
34
|
+
assert_equal true, serve_static_assets?
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_assets_digest?
|
38
|
+
assert_equal false, assets_digest?
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_serve_theme_compiled?
|
42
|
+
assert_equal false, serve_theme_compiled?
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_current_theme
|
46
|
+
assert_equal 'foo', current_theme
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
class ActionViewUseSprocketsTest < ActionView::TestCase
|
52
|
+
tests ThemePark::Rails::AssetTagHelper
|
53
|
+
|
54
|
+
include Sprockets::Helpers::RailsHelper
|
55
|
+
|
56
|
+
def setup
|
57
|
+
super
|
58
|
+
@current_theme = 'foo'
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_theme_javascript_include_tag
|
62
|
+
assert_dom_equal '<script src="/assets/xx.js" type="text/javascript"></script>', theme_javascript_include_tag('xx')
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_theme_stylesheet_link_tag
|
66
|
+
assert_dom_equal '<link href="/assets/xx.css" type="text/css" media="screen" rel="stylesheet"/>', theme_stylesheet_link_tag('xx')
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_theme_image_tag
|
70
|
+
assert_dom_equal '<img alt="Xx" src="/assets/xx.jpg" />', theme_image_tag('xx.jpg')
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
class ActionViewServeThemeCompiledTest < ActionView::TestCase
|
76
|
+
tests ThemePark::Rails::AssetTagHelper
|
77
|
+
|
78
|
+
def setup
|
79
|
+
super
|
80
|
+
@current_theme = 'foo'
|
81
|
+
Dummy::Application.config.assets.digest = true
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_theme_javascript_include_tag
|
85
|
+
assert_dom_equal '<script src="/themes/foo/xx.js" type="text/javascript"></script>', theme_javascript_include_tag('xx')
|
86
|
+
assert_dom_equal '<script src="/themes/bar/xx.js" type="text/javascript"></script>', theme_javascript_include_tag('xx', :theme => 'bar')
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_theme_stylesheet_link_tag
|
90
|
+
assert_dom_equal '<link href="/themes/foo/xx.css" type="text/css" media="screen" rel="stylesheet"/>', theme_stylesheet_link_tag('xx')
|
91
|
+
assert_dom_equal '<link href="/themes/bar/xx.css" type="text/css" media="screen" rel="stylesheet"/>', theme_stylesheet_link_tag('xx', :theme => 'bar')
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_theme_image_tag
|
95
|
+
assert_dom_equal '<img alt="Xx" src="/themes/foo/xx.jpg" />', theme_image_tag('xx.jpg')
|
96
|
+
assert_dom_equal '<img alt="Xx" src="/themes/bar/xx.jpg" />', theme_image_tag('xx.jpg', :theme => 'bar')
|
97
|
+
end
|
98
|
+
|
99
|
+
def teardown
|
100
|
+
Dummy::Application.config.assets.digest = false
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class RailtieTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test 'rails app should have a theme_park option' do
|
6
|
+
theme_park = Dummy::Application.config.theme_park
|
7
|
+
assert_equal(ThemePark, theme_park)
|
8
|
+
assert_equal('themes', theme_park.prefix)
|
9
|
+
assert_equal("#{Dummy::Application.root}/themes", theme_park.base_root)
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'action_view should load ThemePark::Rails::ActionView' do
|
13
|
+
assert ActionView::Base < ThemePark::Rails::AssetTagHelper
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'action_controller should load ThemePark::Rails::ActionController' do
|
17
|
+
assert ActionController::Base < ThemePark::Rails::ActionController
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'config.assets.paths should include ThemePark.assets_path' do
|
21
|
+
assert Dummy::Application.config.assets.paths.include?("#{File.dirname(__FILE__)}/dummy/themes/default/assets/images")
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'rails app route should mount at #{ThemePark.prefix}/:theme_name' do
|
25
|
+
routes = Dummy::Application.routes.routes
|
26
|
+
server = routes.select { |r| r.app.instance_of?(ThemePark::Rails::Server) }.pop
|
27
|
+
assert !server.nil? # mount successful
|
28
|
+
path = server.path.spec.to_s
|
29
|
+
assert_equal('/themes/:theme_name', path) # mount path correct
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/test/server_test.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ThemeParkTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@logic_path = File.dirname(__FILE__)
|
7
|
+
ThemePark.setup do |config|
|
8
|
+
config.base = @logic_path
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_root
|
16
|
+
# default setting
|
17
|
+
assert_equal("/themes", ThemePark.root)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_base_root
|
21
|
+
assert_equal("#{@logic_path}/themes", ThemePark.base_root)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_prefix
|
25
|
+
assert_equal("themes", ThemePark.prefix)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_path_with_theme_name
|
29
|
+
assert_equal("#{@logic_path}/themes/default", ThemePark.path('default'))
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_theme_exist_or_not
|
33
|
+
assert_equal(true, ThemePark.exist?('default'))
|
34
|
+
assert_equal(false, ThemePark.exist?('foo'))
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_interpolate
|
38
|
+
assert_equal("#{@logic_path}/themes/oo/bar/foo", ThemePark.interpolate(':root/oo/:name/foo', 'bar'))
|
39
|
+
assert_equal("/themes/oo/bar/foo", ThemePark.interpolate('/themes/oo/bar/foo', 'bar'))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_images_path
|
43
|
+
assert_equal("#{@logic_path}/themes/default/assets/images", ThemePark.images_path('default'))
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_javascripts_path
|
47
|
+
assert_equal("#{@logic_path}/themes/default/assets/javascripts", ThemePark.javascripts_path('default'))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_stylesheets_path
|
51
|
+
assert_equal("#{@logic_path}/themes/default/assets/stylesheets", ThemePark.stylesheets_path('default'))
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_compiled_path
|
55
|
+
assert_equal("#{@logic_path}/themes/default/assets/compiled", ThemePark.compiled_path('default'))
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_views_path
|
59
|
+
assert_equal("#{@logic_path}/themes/default/views", ThemePark.views_path('default'))
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_assets_path_for_one_theme
|
63
|
+
assets_path = [ "#{@logic_path}/themes/default/assets/images",
|
64
|
+
"#{@logic_path}/themes/default/assets/javascripts",
|
65
|
+
"#{@logic_path}/themes/default/assets/stylesheets"]
|
66
|
+
assert_equal(assets_path, ThemePark.theme_assets_path('default'))
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_assets_path
|
70
|
+
assets_path = [ "#{@logic_path}/themes/default/assets/images",
|
71
|
+
"#{@logic_path}/themes/default/assets/javascripts",
|
72
|
+
"#{@logic_path}/themes/default/assets/stylesheets",
|
73
|
+
"#{@logic_path}/themes/default1/assets/images",
|
74
|
+
"#{@logic_path}/themes/default1/assets/javascripts",
|
75
|
+
"#{@logic_path}/themes/default1/assets/stylesheets"].sort
|
76
|
+
assert_equal(assets_path, ThemePark.assets_path.sort)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|