themeable 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1fec3b1a194206c07f3ccdeb121f0648121c74cb
4
+ data.tar.gz: 77b948755c1d29ba790db5e273c06973beee019f
5
+ SHA512:
6
+ metadata.gz: 124a1b09225454e062193d951b26f8ebeeb8e3c640064e0709b394bb5536b07408c6f330ef7d4f14af6cda93bb80956c268b2a757b35e9613331a555d891b068
7
+ data.tar.gz: 40b8d7fb90386c937670e3c6950d59857642e256e96182da7489d957727f6f99c67d916ceb799572909e367963e1a177fa362541f37e5f59c9d0447c351c7dfe
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 xiaohui
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Themeable
2
+
3
+ You can create theme with this tool, make your Rails app choose theme dynamically.
4
+
5
+ ### Install gem
6
+
7
+ gem i themeable
8
+
9
+ ### Create my theme with command line
10
+
11
+ themeable new famous
12
+
13
+ Now, directory `theme_famous` created with this tool.
14
+
15
+ ### Design my theme
16
+
17
+ Start designing your theme in folder `theme`:
18
+
19
+ ├── theme
20
+ │   ├── assets
21
+ │   │   └── famous
22
+ │   │   ├── application.css
23
+ │   │   ├── application.js
24
+ │   │   └── vendor
25
+ │   └── views
26
+ │   └── layouts
27
+ │   └── application.html.erb
28
+
29
+ ### Use my theme in my Rails project
30
+
31
+ Add gem to Rails app:
32
+
33
+ gem 'theme_famous', path: 'path_of_theme_famous'
34
+
35
+ Use theme in controller:
36
+
37
+ By default you need to remove `views/layouts/application.html.erb` from Rails app, make sure Rails can use theme's layout.
38
+
39
+ class HomeController < ApplicationController
40
+ acts_as_themeable 'famous'
41
+ def index
42
+ end
43
+ end
44
+
45
+ Or, you can make this controller use dynamic themes:
46
+
47
+ class HomeController < ApplicationController
48
+ acts_as_themeable :choose_theme
49
+ def index
50
+ end
51
+
52
+ private
53
+
54
+ def choose_theme
55
+ case params[:theme]
56
+ when 'famous' then 'famous'
57
+ when 'classic' then 'classic'
58
+ else; :none # :none means don't use theme
59
+ end
60
+ end
61
+ end
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Themeable'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :themeable do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,28 @@
1
+ module Themeable
2
+ module ActsAsThemeable
3
+ extend ActiveSupport::Concern
4
+
5
+ class_methods do
6
+ def acts_as_themeable(theme_name)
7
+ instance_eval do
8
+ before_filter :insert_theme_view_path
9
+ end
10
+
11
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
12
+ private
13
+ def __themeable_theme_name
14
+ #{theme_name.is_a?(Symbol) ? "send(:#{theme_name})" : "'#{theme_name}'"}
15
+ end
16
+ def insert_theme_view_path
17
+ theme_name = __themeable_theme_name
18
+ return if theme_name == :none
19
+ view_paths = lookup_context.view_paths.to_a.map(&:to_path)
20
+ theme = Themeable.theme(__themeable_theme_name)
21
+ theme_view_path = File.join(theme.path, 'views')
22
+ lookup_context.view_paths = view_paths.insert(1, theme_view_path)
23
+ end
24
+ RUBY
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,60 @@
1
+ require 'thor'
2
+ require 'active_support/core_ext/string'
3
+
4
+ module Themeable
5
+ class Command < Thor
6
+ include Thor::Actions
7
+ source_root File.expand_path("../../../templates", __FILE__)
8
+
9
+ desc "help [COMMAND]", "View Usage"
10
+ def help(*args)
11
+ super(*args)
12
+ end
13
+
14
+ desc "new THEME_NAME", "Create a new theme"
15
+ def new(name)
16
+ @theme_name = name
17
+ @app_name = "theme_#{name}"
18
+ say('Initializing theme project...', :green)
19
+ # say("\"rails plugin new #{app_name} -T\"")
20
+ system "rails plugin new #{app_name} -T"
21
+
22
+ @destination_stack ||= []
23
+ @destination_stack[0] = File.expand_path(app_name)
24
+
25
+ gsub_file "#{app_name}.gemspec", /TODO[: ]*/, ''
26
+
27
+ insert_into_file "#{app_name}.gemspec", after: %r{^ *s\.add_dependency .*} do
28
+ "\n s.add_dependency 'themeable'"
29
+ end
30
+
31
+ template 'theme_views_generator.rb', "lib/generators/themeable/#{theme_name}/views_generator.rb"
32
+ template 'theme_assets_generator.rb', "lib/generators/themeable/#{theme_name}/assets_generator.rb"
33
+
34
+ create_file "theme/assets/#{theme_name}/vendor/.gitkeep"
35
+ create_file "theme/assets/#{theme_name}/application.css"
36
+ create_file "theme/assets/#{theme_name}/application.js"
37
+ create_file "theme/views/layouts/.gitkeep"
38
+ template "view_application.html.erb", "theme/views/layouts/application.html.erb"
39
+
40
+ remove_file "lib/#{app_name}.rb"
41
+ template 'theme_main.rb', "lib/#{app_name}.rb"
42
+
43
+ puts
44
+ say("Done. Please check your new theme project in directory #{app_name}", :green)
45
+ puts
46
+ end
47
+
48
+ no_tasks do
49
+ def app_name
50
+ @app_name
51
+ end
52
+ def theme_name
53
+ @theme_name
54
+ end
55
+ def set_destination_root(name)
56
+ destination_root = name
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,16 @@
1
+ require 'rails'
2
+ module Themeable
3
+ class Railtie < Rails::Railtie
4
+ config.to_prepare do
5
+ ActionController::Base.send :include, Themeable::ActsAsThemeable
6
+ end
7
+ initializer :themeable do
8
+ # puts "== Themeable =="
9
+ Themeable.themes.each do |theme|
10
+ config.assets.paths << File.join(theme.path, 'assets')
11
+ config.assets.precompile << /\A#{Regexp.escape(theme.name)}\/[^\/]+\.(js|css)\z/
12
+ config.assets.precompile << /\A#{Regexp.escape(theme.name)}\/.+\.(gif|jpg|png|svg)\z/
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,30 @@
1
+ module Themeable
2
+ module Theme
3
+ def self.included(subclass)
4
+ Themeable.add_theme(subclass)
5
+ subclass.instance_eval <<-'RUBY'
6
+
7
+ @name = nil
8
+ def name
9
+ @name || raise("Theme name is no defined")
10
+ end
11
+
12
+ @path = nil
13
+ def path
14
+ @path || raise("Theme path is no defined")
15
+ end
16
+
17
+ private
18
+
19
+ def set_name(name)
20
+ @name = name.to_sym
21
+ end
22
+
23
+ def set_path(path)
24
+ @path = path
25
+ end
26
+
27
+ RUBY
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Themeable
2
+ VERSION = "1.0.0"
3
+ end
data/lib/themeable.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'themeable/version'
2
+ require 'themeable/railtie'
3
+ require 'themeable/theme'
4
+ require 'themeable/acts_as_themeable'
5
+
6
+ module Themeable
7
+
8
+ @@theme_set = Set.new
9
+ def self.add_theme(theme_class)
10
+ @@theme_set << theme_class
11
+ end
12
+
13
+ def self.themes
14
+ @@theme_set
15
+ end
16
+
17
+ def self.theme(theme_name)
18
+ themes.find{|t| t.name == theme_name.to_sym } || raise("Theme #{theme_name} not found")
19
+ end
20
+
21
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: themeable
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - xiaohui
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-05 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.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Creating theme, and puting into your Rails app
56
+ email:
57
+ - xiaohui@zhangxh.net
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - lib/tasks/themeable_tasks.rake
66
+ - lib/themeable.rb
67
+ - lib/themeable/acts_as_themeable.rb
68
+ - lib/themeable/command.rb
69
+ - lib/themeable/railtie.rb
70
+ - lib/themeable/theme.rb
71
+ - lib/themeable/version.rb
72
+ homepage: https://github.com/xiaohui-zhangxh/
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.8
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: A tool for creating theme.
96
+ test_files: []