shiny_themes 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +34 -0
  4. data/lib/generators/shiny_themes/install_generator.rb +19 -0
  5. data/lib/generators/shiny_themes/templates/application.html.erb +14 -0
  6. data/lib/generators/shiny_themes/templates/manifest.css +14 -0
  7. data/lib/generators/shiny_themes/templates/manifest.js +9 -0
  8. data/lib/generators/shiny_themes/templates/manifest.scss +12 -0
  9. data/lib/generators/shiny_themes/templates/theme.yml +8 -0
  10. data/lib/generators/shiny_themes/theme_generator.rb +50 -0
  11. data/lib/shiny_themes.rb +8 -0
  12. data/lib/shiny_themes/engine.rb +56 -0
  13. data/lib/shiny_themes/renders_theme.rb +53 -0
  14. data/lib/shiny_themes/theme.rb +76 -0
  15. data/lib/shiny_themes/theme_config.rb +45 -0
  16. data/lib/shiny_themes/version.rb +3 -0
  17. data/test/dummy/README.rdoc +28 -0
  18. data/test/dummy/Rakefile +6 -0
  19. data/test/dummy/app/assets/javascripts/application.js +13 -0
  20. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  21. data/test/dummy/app/controllers/application_controller.rb +5 -0
  22. data/test/dummy/app/helpers/application_helper.rb +2 -0
  23. data/test/dummy/app/themes/test_theme/views/layouts/test_layout.html.erb +14 -0
  24. data/test/dummy/app/themes/test_theme/views/shiny_themes/test/test.html.erb +1 -0
  25. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  26. data/test/dummy/bin/bundle +3 -0
  27. data/test/dummy/bin/rails +4 -0
  28. data/test/dummy/bin/rake +4 -0
  29. data/test/dummy/bin/setup +29 -0
  30. data/test/dummy/config.ru +4 -0
  31. data/test/dummy/config/application.rb +29 -0
  32. data/test/dummy/config/boot.rb +5 -0
  33. data/test/dummy/config/environment.rb +5 -0
  34. data/test/dummy/config/environments/development.rb +38 -0
  35. data/test/dummy/config/environments/production.rb +76 -0
  36. data/test/dummy/config/environments/test.rb +42 -0
  37. data/test/dummy/config/initializers/assets.rb +11 -0
  38. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  40. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  41. data/test/dummy/config/initializers/inflections.rb +16 -0
  42. data/test/dummy/config/initializers/mime_types.rb +4 -0
  43. data/test/dummy/config/initializers/session_store.rb +3 -0
  44. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  45. data/test/dummy/config/locales/en.yml +23 -0
  46. data/test/dummy/config/routes.rb +56 -0
  47. data/test/dummy/config/secrets.yml +22 -0
  48. data/test/dummy/config/theme.yml +4 -0
  49. data/test/dummy/log/test.log +11146 -0
  50. data/test/dummy/public/404.html +67 -0
  51. data/test/dummy/public/422.html +67 -0
  52. data/test/dummy/public/500.html +66 -0
  53. data/test/dummy/public/favicon.ico +0 -0
  54. data/test/dummy/tmp/app/themes/temp_theme/assets/javascripts/temp_theme/manifest.js +9 -0
  55. data/test/dummy/tmp/app/themes/temp_theme/assets/stylesheets/temp_theme/manifest.css +14 -0
  56. data/test/dummy/tmp/app/themes/temp_theme/views/layouts/temp_layout.html.erb +14 -0
  57. data/test/generators/shiny_themes/install_generator_test.rb +23 -0
  58. data/test/generators/shiny_themes/theme_generator_test.rb +59 -0
  59. data/test/lib/engine_test.rb +73 -0
  60. data/test/lib/renders_theme_test.rb +72 -0
  61. data/test/lib/theme_config_test.rb +60 -0
  62. data/test/lib/theme_test.rb +115 -0
  63. data/test/support/theme_test_helper.rb +23 -0
  64. data/test/test_helper.rb +19 -0
  65. metadata +169 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,9 @@
1
+ /* Manifest javascript
2
+ * Use this to import all javascripts for your theme. If you want to
3
+ * import javascript files in different pages or layouts simply create
4
+ * another manifest file and begin the name with 'manifest_' or 'manifest-'
5
+ */
6
+ // Require this JS file
7
+ //=require_self
8
+ // Require all javascripts in the current directory
9
+ //=require_tree .
@@ -0,0 +1,14 @@
1
+ /* manifest stylesheet
2
+ * Use this to import all stylesheets for your theme. If you want to
3
+ * import stylesheets in different pages or layouts simply create another
4
+ * manifest file and begin the name with 'manifest_' or 'manifest-'
5
+ *
6
+ * The CSS extension manifests will use require comments that sprockets
7
+ * uses to import stylesheets. Generate a sass theme to use the sass
8
+ * import syntax.
9
+ *
10
+ * Require this stylesheet
11
+ *=require_self
12
+ * Require all stylesheets in the current directory
13
+ *=require_tree .
14
+ */
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= theme_name %></title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+ require 'generators/shiny_themes/install_generator'
3
+
4
+ class InstallGeneratorTest < Rails::Generators::TestCase
5
+ tests ShinyThemes::Generators::InstallGenerator
6
+ destination Rails.root.join('tmp')
7
+ # Reload theme config
8
+ ShinyThemes::Engine.theme_config.load
9
+
10
+ def setup
11
+ prepare_destination
12
+ run_generator
13
+ end
14
+ setup :prepare_destination
15
+
16
+ test "it copies the theme configuration" do
17
+ assert_file "config/theme.yml"
18
+ end
19
+
20
+ test "it creates a theme directory" do
21
+ assert_file "app/themes"
22
+ end
23
+ end
@@ -0,0 +1,59 @@
1
+ require 'test_helper'
2
+ require 'generators/shiny_themes/theme_generator'
3
+
4
+ class ThemeGeneratorTest < Rails::Generators::TestCase
5
+ tests ShinyThemes::Generators::ThemeGenerator
6
+ destination Rails.root.join('tmp')
7
+
8
+ def setup
9
+ # Reload theme config
10
+ ShinyThemes::Engine.theme_config.load
11
+ prepare_destination
12
+ @theme_name, @layout_name = 'temp_theme', 'temp_layout'
13
+ end
14
+
15
+ def theme_directory
16
+ Pathname.new(File.join('app', 'themes', @theme_name))
17
+ end
18
+
19
+ test 'creates layout directory' do
20
+ run_generator([@theme_name, "--layout=#{@layout_name}"])
21
+ assert_file(theme_directory.join('views', 'layouts'))
22
+ end
23
+
24
+ test 'creates images directory' do
25
+ run_generator([@theme_name, "--layout=#{@layout_name}"])
26
+ assert_file(theme_directory.join('assets', 'images', @theme_name, '.gitkeep'))
27
+ end
28
+
29
+ test 'creates javascripts directory' do
30
+ run_generator([@theme_name, "--layout=#{@layout_name}"])
31
+ assert_file(theme_directory.join('assets', 'javascripts', @theme_name, '.gitkeep'))
32
+ end
33
+
34
+ test 'creates stylesheets directory' do
35
+ run_generator([@theme_name, "--layout=#{@layout_name}"])
36
+ assert_file(theme_directory.join('assets', 'stylesheets', @theme_name, '.gitkeep'))
37
+ end
38
+
39
+ test 'creates JS manifest' do
40
+ run_generator([@theme_name, "--layout=#{@layout_name}"])
41
+ assert_file(theme_directory.join('assets', 'javascripts', @theme_name, 'manifest.js'))
42
+ end
43
+
44
+ test 'creates CSS manifest when sass is false' do
45
+ run_generator([@theme_name, "--layout=#{@layout_name}"])
46
+ assert_file(theme_directory.join('assets', 'stylesheets', @theme_name, 'manifest.css'))
47
+ end
48
+
49
+ test 'creates an SCSS manifest when sass is true' do
50
+ run_generator([@theme_name, "--layout=#{@layout_name}", "--sass"])
51
+ assert_file(theme_directory.join('assets', 'stylesheets', @theme_name, 'manifest.scss'))
52
+ end
53
+
54
+ test 'creates a layout using the name provided' do
55
+ run_generator([@theme_name, "--layout=#{@layout_name}"])
56
+ assert_file(theme_directory.join('views', 'layouts', "#{@layout_name}.html.erb"))
57
+ end
58
+
59
+ end
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+
3
+ class EngineTest < ActiveSupport::TestCase
4
+ include ThemeTestHelper
5
+
6
+ def setup
7
+ # Reload theme config
8
+ ShinyThemes::Engine.theme_config.load
9
+ @themes_path = Rails.root.join(Rails.application.config.theme.path)
10
+ # Grab all directory names in themes_path to get all installed theme names
11
+ @theme_names = Dir.glob(@themes_path.join('*/')).map{ |fn| Pathname.new(fn).basename }
12
+ @theme_config = YAML.load_file(Rails.root.join('config', 'theme.yml'))[Rails.env]
13
+ end
14
+
15
+ test 'theme config ordered options created' do
16
+ assert_instance_of(ActiveSupport::OrderedOptions, Rails.application.config.theme,
17
+ 'Theme config should be an ordered options instance')
18
+ end
19
+
20
+ test 'default theme path configured' do
21
+ assert_equal(File.join('app', 'themes'), Rails.application.config.theme.path)
22
+ end
23
+
24
+ test 'theme asset directories configured' do
25
+ assert_includes(Rails.application.config.theme.asset_directories, 'images',
26
+ 'Images must be part of theme asset_directories by default')
27
+ assert_includes(Rails.application.config.theme.asset_directories, 'stylesheets',
28
+ 'Stylesheets must be part of theme asset_directories by default')
29
+ assert_includes(Rails.application.config.theme.asset_directories, 'javascripts',
30
+ 'Javascripts must be part of theme asset_directories by default')
31
+ end
32
+
33
+ test 'theme name configured from yml file' do
34
+ assert_equal(@theme_config[:name], Rails.application.config.theme.name, 'Theme name in config must match theme.yml')
35
+ end
36
+
37
+ test 'theme layout configured from yml file' do
38
+ assert_equal(@theme_config[:layout], Rails.application.config.theme.layout, 'Theme layout in config must match theme.yml')
39
+ end
40
+
41
+ test 'all themes asset images directories added to assets path' do
42
+ @theme_names.each do |theme_name|
43
+ assert_includes(Rails.application.config.assets.paths, @themes_path.join(theme_name, 'assets', 'images').to_s,
44
+ 'Asset path should include images directories for all themes')
45
+ assert_includes(Rails.application.config.assets.paths, @themes_path.join(theme_name, 'assets', 'images', theme_name).to_s,
46
+ 'Asset path should include images namespaced directories for all themes')
47
+ end
48
+ end
49
+
50
+ test 'all themes asset javascripts directories added to assets path' do
51
+ @theme_names.each do |theme_name|
52
+ assert_includes(Rails.application.config.assets.paths, @themes_path.join(theme_name, 'assets', 'javascripts').to_s,
53
+ 'Asset path should include javascripts directories for all themes')
54
+ assert_includes(Rails.application.config.assets.paths, @themes_path.join(theme_name, 'assets', 'javascripts', theme_name).to_s,
55
+ 'Asset path should include javascripts namespaced directories for all themes')
56
+ end
57
+ end
58
+
59
+ test 'all themes asset stylesheets directories added to assets path' do
60
+ @theme_names.each do |theme_name|
61
+ assert_includes(Rails.application.config.assets.paths, @themes_path.join(theme_name, 'assets', 'stylesheets').to_s,
62
+ 'Asset path should include stylesheets directories for all themes')
63
+ assert_includes(Rails.application.config.assets.paths, @themes_path.join(theme_name, 'assets', 'stylesheets', theme_name).to_s,
64
+ 'Asset path should include stylesheets namespaced directories for all themes')
65
+ end
66
+ end
67
+
68
+ test 'includes RendersTheme in application controller' do
69
+ assert_respond_to(ApplicationController, :renders_theme)
70
+ assert_respond_to(ApplicationController, :theme)
71
+ end
72
+
73
+ end
@@ -0,0 +1,72 @@
1
+ require 'test_helper'
2
+
3
+ module ShinyThemes
4
+ include ::ThemeTestHelper
5
+ class TestController < ActionController::Base
6
+ def test
7
+ render 'test'
8
+ end
9
+ end
10
+
11
+ # If disable_clear_and_finalize is set to true, Rails will not clear other routes when calling again the draw method.
12
+ # Look at the source code at: http://apidock.com/rails/v4.0.2/ActionDispatch/Routing/RouteSet/draw
13
+ Rails.application.routes.disable_clear_and_finalize = true
14
+
15
+ # Create a new route for our new action
16
+ Rails.application.routes.draw do
17
+ get 'test' => 'shiny_themes/test#test'
18
+ end
19
+
20
+ class RendersThemeTest < ActionController::TestCase
21
+ tests TestController
22
+ # Reload theme config
23
+ ShinyThemes::Engine.theme_config.load
24
+ @@original_theme = TestController.theme
25
+ @@original_config = Rails.application.config.theme.clone
26
+
27
+ def teardown
28
+ @controller.class.theme = @@original_theme
29
+ Rails.application.config.theme = @@original_config.clone
30
+ ShinyThemes::Engine.theme_config.save
31
+ end
32
+
33
+ test 'included controller has theme class attribute' do
34
+ assert_includes(@controller.class.class_variables, :@@theme)
35
+ assert_respond_to(@controller, :theme)
36
+ assert_kind_of(ShinyThemes::Theme, @controller.class.theme)
37
+ end
38
+
39
+ test 'theme is created from config file' do
40
+ theme_config = YAML.load_file(Rails.root.join('config', 'theme.yml'))[Rails.env]
41
+ assert_equal(@controller.class.theme.name, theme_config[:name])
42
+ assert_equal(@controller.class.theme.layout, theme_config[:layout])
43
+ end
44
+
45
+ test 'uses layout from controller theme' do
46
+ get :test
47
+ assert_template(layout: @controller.class.theme.layout)
48
+ end
49
+
50
+ test 'prepends template views to controller view paths' do
51
+ get :test
52
+ assert_includes(@controller.view_paths.paths.map(&:to_s), @controller.class.theme.views_path.to_s)
53
+ end
54
+
55
+ test '.renders_theme changes controller theme and layout' do
56
+ test_theme_name, test_theme_layout = 'temp_theme', 'temp_layout'
57
+ @controller.class_eval do
58
+ renders_theme test_theme_name, layout: test_theme_layout
59
+ end
60
+ assert_equal(test_theme_name, @controller.class.theme.name)
61
+ assert_equal(test_theme_layout, @controller.class.theme.layout)
62
+ end
63
+
64
+ test '#update_current_theme changes controller theme and layout' do
65
+ test_theme_name, test_theme_layout = 'temp_theme', 'temp_layout'
66
+ @controller.update_current_theme(test_theme_name, layout: test_theme_layout)
67
+ assert_equal(test_theme_name, @controller.class.theme.name)
68
+ assert_equal(test_theme_layout, @controller.class.theme.layout)
69
+ end
70
+
71
+ end
72
+ end