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,60 @@
1
+ require 'test_helper'
2
+
3
+ class ThemeConfigTest < ActiveSupport::TestCase
4
+ # Reload theme config
5
+ ShinyThemes::Engine.theme_config.load
6
+ @@original_config = Rails.application.config.theme.clone
7
+
8
+
9
+ def setup
10
+ Rails.application.config.theme = nil
11
+ @theme_config = ShinyThemes::ThemeConfig.new
12
+ end
13
+
14
+ def teardown
15
+ Rails.application.config.theme = @@original_config
16
+ end
17
+
18
+ test 'creates new theme config on rails application' do
19
+ refute_nil(Rails.application.config.theme, 'Creating a new config should create an empty theme config')
20
+ assert_kind_of(ActiveSupport::OrderedOptions, Rails.application.config.theme,
21
+ 'Creating a new config should create an ActiveSupport::OrderedOptions object')
22
+ end
23
+
24
+ test 'loads theme config from config_pathname' do
25
+ yaml_config = YAML.load(File.open(@theme_config.config_pathname))[Rails.env]
26
+ @theme_config.load
27
+ assert_equal(yaml_config[:name], Rails.application.config.theme.name,
28
+ 'Loading config should populate theme name from YAML file')
29
+ assert_equal(yaml_config[:layout], Rails.application.config.theme.layout,
30
+ 'Loading config should populate theme layout from YAML file')
31
+ end
32
+
33
+ test 'honors config value over default' do
34
+ yaml_config = YAML.load(File.open(@theme_config.config_pathname))
35
+ yaml_config[Rails.env]['path'] = '/other/path'
36
+ File.open(@theme_config.config_pathname, 'w') { |f| f << yaml_config.to_yaml }
37
+
38
+ @theme_config.load
39
+ assert_equal('/other/path', Rails.application.config.theme.path)
40
+
41
+ # Revert changes to YAML file
42
+ yaml_config[Rails.env].delete('path')
43
+ File.open(@theme_config.config_pathname, 'w') { |f| f << yaml_config.stringify_keys.to_yaml }
44
+ end
45
+
46
+ test 'saves current config to yaml file' do
47
+ @theme_config.load
48
+ test_theme_name, test_theme_layout = 'dummy_value', 'dummy_layout'
49
+ Rails.application.config.theme.name = test_theme_name
50
+ Rails.application.config.theme.layout = test_theme_layout
51
+ @theme_config.save
52
+
53
+ yaml_config = YAML.load(File.open(@theme_config.config_pathname))[Rails.env]
54
+ assert_equal(test_theme_name, yaml_config[:name], 'Saving config should update theme name in YAML file')
55
+ assert_equal(test_theme_layout, yaml_config[:layout], 'Saving config should update theme layout in YAML file')
56
+
57
+ Rails.application.config.theme = @@original_config
58
+ @theme_config.save
59
+ end
60
+ end
@@ -0,0 +1,115 @@
1
+ require 'test_helper'
2
+ require 'fileutils'
3
+
4
+ class ThemeTest < ActiveSupport::TestCase
5
+ include ThemeTestHelper
6
+
7
+ def setup
8
+ @theme_name, @layout_name = 'temp_theme', 'temp_layout'
9
+ ShinyThemes::Engine.theme_config.load
10
+ # Create theme directories
11
+ build_theme_dir(@theme_name)
12
+ end
13
+
14
+ def teardown
15
+ @theme = nil
16
+ # Destroy root theme directory
17
+ cleanup_theme_dir(@theme_name)
18
+ # Reload the default config after any test modifications
19
+ ShinyThemes::Engine.theme_config.load
20
+ end
21
+
22
+ def theme
23
+ @theme ||= ShinyThemes::Theme.new(name: @theme_name, layout: @layout_name)
24
+ end
25
+
26
+ test "is valid with name, layout and valid directory structure" do
27
+ assert(theme.valid?, 'Theme with name, layout and valid directory structure should be valid')
28
+ end
29
+
30
+ test "theme is invalid without name" do
31
+ original_theme_name, @theme_name = @theme_name, ''
32
+ refute(theme.valid?, 'Theme without a name should not be valid')
33
+ assert_includes(theme.errors.keys, :name, 'Theme without a name should have a "name" related error')
34
+ @theme_name = original_theme_name
35
+ end
36
+
37
+ test "theme is invalid without a layout" do
38
+ @layout_name = ''
39
+ refute(theme.valid?, 'Theme without a layout should not be valid')
40
+ assert_includes(theme.errors.keys, :layout, 'Theme without a layout should have a "layout" related error')
41
+ end
42
+
43
+ test "theme is invalid without any directories" do
44
+ cleanup_theme_dir(@theme_name)
45
+ refute(theme.valid?, 'Theme without a valid directory structure should not be valid')
46
+ assert_includes(theme.errors.keys, :base, 'Theme without a valid directory structure should have a "base" related error')
47
+ end
48
+
49
+ test "theme is invalid without a views directory" do
50
+ FileUtils.rmtree(theme_root.join(@theme_name, 'views'))
51
+ refute(theme.valid?, 'Theme without a views directory should not be valid')
52
+ assert_includes(theme.errors.keys, :base, 'Theme without a views directory should have a "base" related error')
53
+ end
54
+
55
+ test "theme is invalid without an assets directory" do
56
+ FileUtils.rmtree(theme_root.join(@theme_name, 'assets'))
57
+ refute(theme.valid?, 'Theme without a views directory should not be valid')
58
+ assert_includes(theme.errors.keys, :base, 'Theme without an assets directory should have a "base" related error')
59
+ end
60
+
61
+ test "theme is invalid without an assets/images directory" do
62
+ FileUtils.rmtree(theme_root.join(@theme_name, 'assets', 'images'))
63
+ refute(theme.valid?, 'Theme without an assets/images directory should not be valid')
64
+ assert_includes(theme.errors.keys, :base, 'Theme without an assets/images directory should have a "base" related error')
65
+ end
66
+
67
+ test "theme is invalid without an assets/stylesheets directory" do
68
+ FileUtils.rmtree(theme_root.join(@theme_name, 'assets', 'stylesheets'))
69
+ refute(theme.valid?, 'Theme without an assets/stylesheets directory should not be valid')
70
+ assert_includes(theme.errors.keys, :base, 'Theme without an assets/stylesheets directory should have a "base" related error')
71
+ end
72
+
73
+ test "theme is invalid without an assets/javascripts directory" do
74
+ FileUtils.rmtree(theme_root.join(@theme_name, 'assets', 'javascripts'))
75
+ refute(theme.valid?, 'Theme without an assets/javascripts directory should not be valid')
76
+ assert_includes(theme.errors.keys, :base, 'Theme without an assets/javascripts directory should have a "base" related error')
77
+ end
78
+
79
+ test "theme is invalid without a images asset namespace directory" do
80
+ FileUtils.rmtree(theme_root.join(@theme_name, 'assets', 'images', @theme_name))
81
+ refute(theme.valid?, 'Theme without an assets/images directory should not be valid')
82
+ assert_includes(theme.errors.keys, :base, 'Theme without an assets/images directory should have a "base" related error')
83
+ end
84
+
85
+ test "theme is invalid without a stylesheets asset namespace directory" do
86
+ FileUtils.rmtree(theme_root.join(@theme_name, 'assets', 'stylesheets', @theme_name))
87
+ refute(theme.valid?, 'Theme without an assets/images directory should not be valid')
88
+ assert_includes(theme.errors.keys, :base, 'Theme without an assets/images directory should have a "base" related error')
89
+ end
90
+
91
+ test "theme is invalid without a javascripts asset namespace directory" do
92
+ FileUtils.rmtree(theme_root.join(@theme_name, 'assets', 'javascripts', @theme_name))
93
+ refute(theme.valid?, 'Theme without an assets/images directory should not be valid')
94
+ assert_includes(theme.errors.keys, :base, 'Theme without an assets/images directory should have a "base" related error')
95
+ end
96
+
97
+ test "uses theme configuration for default name" do
98
+ refute_nil(Rails.application.config.theme.name)
99
+ original_theme_name, @theme_name = @theme_name, nil
100
+ assert_equal(Rails.application.config.theme.name, theme.name, 'Theme name should default to config.theme.name value')
101
+ @theme_name = original_theme_name
102
+ end
103
+
104
+ test "uses theme configuration for default layout" do
105
+ refute_nil(Rails.application.config.theme.layout)
106
+ @layout_name = nil
107
+ assert_equal(Rails.application.config.theme.layout, theme.layout, 'Theme layout should defualt to config.theme.layout value')
108
+ end
109
+
110
+ test "uses application for default layout when config value is missing" do
111
+ Rails.application.config.theme.layout = nil
112
+ @layout_name = nil
113
+ assert_equal('application', theme.layout, 'Theme layout should default to "application" when config value not present')
114
+ end
115
+ end
@@ -0,0 +1,23 @@
1
+ require 'fileutils'
2
+ module ThemeTestHelper
3
+
4
+ # Create theme directories
5
+ # @param name [String] name of the theme to build directories for
6
+ def build_theme_dir(name)
7
+ FileUtils.mkdir_p(theme_root.join(name, 'views'))
8
+ Rails.application.config.theme.asset_directories.each do |asset_dir_name|
9
+ FileUtils.mkdir_p(theme_root.join(name, 'assets', asset_dir_name, name))
10
+ end
11
+ end
12
+
13
+ # Remove root theme directory
14
+ # @param name [String] name of the theme to remove root directory for
15
+ def cleanup_theme_dir(name)
16
+ FileUtils.rmtree(theme_root.join(name)) if Dir.exists?(theme_root.join(name))
17
+ end
18
+
19
+ # @return [Pathname] path to the root themes directory
20
+ def theme_root
21
+ @theme_root ||= Rails.root.join(Rails.application.config.theme.path)
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
8
+ # to be shown.
9
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
10
+
11
+ # Load support files
12
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
13
+
14
+ # Load fixtures from the engine
15
+ if ActiveSupport::TestCase.respond_to?(:fixture_path=)
16
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
17
+ ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
18
+ ActiveSupport::TestCase.fixtures :all
19
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shiny_themes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - shinylane
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.5.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.5.1
27
+ description: Generate and manage themes which are made up of templates and assets.
28
+ email:
29
+ - roblane09@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - Rakefile
36
+ - lib/generators/shiny_themes/install_generator.rb
37
+ - lib/generators/shiny_themes/templates/application.html.erb
38
+ - lib/generators/shiny_themes/templates/manifest.css
39
+ - lib/generators/shiny_themes/templates/manifest.js
40
+ - lib/generators/shiny_themes/templates/manifest.scss
41
+ - lib/generators/shiny_themes/templates/theme.yml
42
+ - lib/generators/shiny_themes/theme_generator.rb
43
+ - lib/shiny_themes.rb
44
+ - lib/shiny_themes/engine.rb
45
+ - lib/shiny_themes/renders_theme.rb
46
+ - lib/shiny_themes/theme.rb
47
+ - lib/shiny_themes/theme_config.rb
48
+ - lib/shiny_themes/version.rb
49
+ - test/dummy/README.rdoc
50
+ - test/dummy/Rakefile
51
+ - test/dummy/app/assets/javascripts/application.js
52
+ - test/dummy/app/assets/stylesheets/application.css
53
+ - test/dummy/app/controllers/application_controller.rb
54
+ - test/dummy/app/helpers/application_helper.rb
55
+ - test/dummy/app/themes/test_theme/views/layouts/test_layout.html.erb
56
+ - test/dummy/app/themes/test_theme/views/shiny_themes/test/test.html.erb
57
+ - test/dummy/app/views/layouts/application.html.erb
58
+ - test/dummy/bin/bundle
59
+ - test/dummy/bin/rails
60
+ - test/dummy/bin/rake
61
+ - test/dummy/bin/setup
62
+ - test/dummy/config.ru
63
+ - test/dummy/config/application.rb
64
+ - test/dummy/config/boot.rb
65
+ - test/dummy/config/environment.rb
66
+ - test/dummy/config/environments/development.rb
67
+ - test/dummy/config/environments/production.rb
68
+ - test/dummy/config/environments/test.rb
69
+ - test/dummy/config/initializers/assets.rb
70
+ - test/dummy/config/initializers/backtrace_silencers.rb
71
+ - test/dummy/config/initializers/cookies_serializer.rb
72
+ - test/dummy/config/initializers/filter_parameter_logging.rb
73
+ - test/dummy/config/initializers/inflections.rb
74
+ - test/dummy/config/initializers/mime_types.rb
75
+ - test/dummy/config/initializers/session_store.rb
76
+ - test/dummy/config/initializers/wrap_parameters.rb
77
+ - test/dummy/config/locales/en.yml
78
+ - test/dummy/config/routes.rb
79
+ - test/dummy/config/secrets.yml
80
+ - test/dummy/config/theme.yml
81
+ - test/dummy/log/test.log
82
+ - test/dummy/public/404.html
83
+ - test/dummy/public/422.html
84
+ - test/dummy/public/500.html
85
+ - test/dummy/public/favicon.ico
86
+ - test/dummy/tmp/app/themes/temp_theme/assets/javascripts/temp_theme/manifest.js
87
+ - test/dummy/tmp/app/themes/temp_theme/assets/stylesheets/temp_theme/manifest.css
88
+ - test/dummy/tmp/app/themes/temp_theme/views/layouts/temp_layout.html.erb
89
+ - test/generators/shiny_themes/install_generator_test.rb
90
+ - test/generators/shiny_themes/theme_generator_test.rb
91
+ - test/lib/engine_test.rb
92
+ - test/lib/renders_theme_test.rb
93
+ - test/lib/theme_config_test.rb
94
+ - test/lib/theme_test.rb
95
+ - test/support/theme_test_helper.rb
96
+ - test/test_helper.rb
97
+ homepage: https://github.com/rob-lane/shiny_themes
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.5.2
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: A simple Rails theme plugin
121
+ test_files:
122
+ - test/dummy/app/assets/javascripts/application.js
123
+ - test/dummy/app/assets/stylesheets/application.css
124
+ - test/dummy/app/controllers/application_controller.rb
125
+ - test/dummy/app/helpers/application_helper.rb
126
+ - test/dummy/app/themes/test_theme/views/layouts/test_layout.html.erb
127
+ - test/dummy/app/themes/test_theme/views/shiny_themes/test/test.html.erb
128
+ - test/dummy/app/views/layouts/application.html.erb
129
+ - test/dummy/bin/bundle
130
+ - test/dummy/bin/rails
131
+ - test/dummy/bin/rake
132
+ - test/dummy/bin/setup
133
+ - test/dummy/config/application.rb
134
+ - test/dummy/config/boot.rb
135
+ - test/dummy/config/environment.rb
136
+ - test/dummy/config/environments/development.rb
137
+ - test/dummy/config/environments/production.rb
138
+ - test/dummy/config/environments/test.rb
139
+ - test/dummy/config/initializers/assets.rb
140
+ - test/dummy/config/initializers/backtrace_silencers.rb
141
+ - test/dummy/config/initializers/cookies_serializer.rb
142
+ - test/dummy/config/initializers/filter_parameter_logging.rb
143
+ - test/dummy/config/initializers/inflections.rb
144
+ - test/dummy/config/initializers/mime_types.rb
145
+ - test/dummy/config/initializers/session_store.rb
146
+ - test/dummy/config/initializers/wrap_parameters.rb
147
+ - test/dummy/config/locales/en.yml
148
+ - test/dummy/config/routes.rb
149
+ - test/dummy/config/secrets.yml
150
+ - test/dummy/config/theme.yml
151
+ - test/dummy/config.ru
152
+ - test/dummy/log/test.log
153
+ - test/dummy/public/404.html
154
+ - test/dummy/public/422.html
155
+ - test/dummy/public/500.html
156
+ - test/dummy/public/favicon.ico
157
+ - test/dummy/Rakefile
158
+ - test/dummy/README.rdoc
159
+ - test/dummy/tmp/app/themes/temp_theme/assets/javascripts/temp_theme/manifest.js
160
+ - test/dummy/tmp/app/themes/temp_theme/assets/stylesheets/temp_theme/manifest.css
161
+ - test/dummy/tmp/app/themes/temp_theme/views/layouts/temp_layout.html.erb
162
+ - test/generators/shiny_themes/install_generator_test.rb
163
+ - test/generators/shiny_themes/theme_generator_test.rb
164
+ - test/lib/engine_test.rb
165
+ - test/lib/renders_theme_test.rb
166
+ - test/lib/theme_config_test.rb
167
+ - test/lib/theme_test.rb
168
+ - test/support/theme_test_helper.rb
169
+ - test/test_helper.rb