themeable 1.0.2 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa6d3445f0046219df9a252081e25219a8fcb5c2
4
- data.tar.gz: 5aaa8a8c34245b06311d348652f258f35e5cac98
3
+ metadata.gz: 226dd22ad75dcbfb96aa75860a0c8cb733cedfec
4
+ data.tar.gz: 9dc9079e67e956c5486543615891f0ab19cc6ffb
5
5
  SHA512:
6
- metadata.gz: 0c505f3ca0972da747652603733b79aa74d267d316bbe55370bb0e86266454016b6bf80a5cba0811d6024f3aef1176435505d6eac0c83df8f8b7cb7cae00e9bb
7
- data.tar.gz: 5f16c93af12deaa041f7fa9e7d537b9cf97903cb0ee5c6d3e0e9520be3fa62b306ee166cb8092b596168c9eec44eef2bf31e8fffcd5dc56ee27f404aac739dd2
6
+ metadata.gz: 33dffd44dd810e344ed29ec70625221a950588f341da2054950aea59e9ec1094e966011bffe221e2c49be4db32b3524141a74d3d417ee110811e946c8fe73b2d
7
+ data.tar.gz: d2ffc2a5423dacc228742ba9f8bea34548242aeba590bcc7efb93277a4ae6f71d1a1db5c4235cbc6e0b5592bf8715df387dfc5fb8120979d5a69af9f3d90e83c
@@ -18,7 +18,7 @@ module Themeable
18
18
  return if theme_name == :none
19
19
  view_paths = lookup_context.view_paths.to_a.map(&:to_path)
20
20
  theme = Themeable.theme(__themeable_theme_name)
21
- theme_view_path = File.join(theme.path, 'views')
21
+ theme_view_path = File.join(theme.root_path, theme.theme_path, 'views')
22
22
  lookup_context.view_paths = view_paths.insert(1, theme_view_path)
23
23
  end
24
24
  RUBY
@@ -31,15 +31,20 @@ module Themeable
31
31
  "\n s.add_dependency 'themeable'"
32
32
  end
33
33
 
34
+ # generators
34
35
  template 'theme_views_generator.rb', "lib/generators/themeable/#{theme_name}/views_generator.rb"
35
36
  template 'theme_assets_generator.rb', "lib/generators/themeable/#{theme_name}/assets_generator.rb"
36
37
 
37
- create_file "theme/assets/#{theme_name}/vendor/.gitkeep"
38
+ # assets and views
38
39
  create_file "theme/assets/#{theme_name}/application.css"
39
40
  create_file "theme/assets/#{theme_name}/application.js"
40
41
  create_file "theme/views/layouts/.gitkeep"
41
42
  template "view_application.html.erb", "theme/views/layouts/application.html.erb"
42
43
 
44
+ # vender files
45
+ create_file "vendor/#{theme_name}/.gitkeep"
46
+
47
+ # libs
43
48
  remove_file "lib/#{app_name}.rb"
44
49
  template 'theme_main.rb', "lib/#{app_name}.rb"
45
50
 
@@ -5,9 +5,9 @@ module Themeable
5
5
  ActionController::Base.send :include, Themeable::ActsAsThemeable
6
6
  end
7
7
  initializer :themeable do
8
- # puts "== Themeable =="
9
8
  Themeable.themes.each do |theme|
10
- config.assets.paths << File.join(theme.path, 'assets')
9
+ config.assets.paths << File.join(theme.root_path, theme.theme_path, 'assets')
10
+ config.assets.paths << File.join(theme.root_path, 'vendor')
11
11
  config.assets.precompile << /\A#{Regexp.escape(theme.name)}\/[^\/]+\.(js|css)\z/
12
12
  config.assets.precompile << /\A#{Regexp.escape(theme.name)}\/.+\.(gif|jpg|png|svg)\z/
13
13
  end
@@ -1,27 +1,71 @@
1
1
  module Themeable
2
+
3
+ # Theme's basic module, automatically define methods
4
+ # - name
5
+ # - root_path
6
+ # - theme_path
2
7
  module Theme
3
8
  def self.included(subclass)
9
+
4
10
  Themeable.add_theme(subclass)
5
- subclass.instance_eval <<-'RUBY'
6
-
7
- @name = nil
11
+
12
+ # set default values
13
+ caller_file = caller.first
14
+ if caller_file =~ %r{/theme_(.+?)/lib/theme_\1\.rb}
15
+ default_name = $1.to_sym
16
+ default_root = File.expand_path(File.join(caller_file, '../../'))
17
+ end
18
+
19
+ subclass.instance_eval <<-RUBY, __FILE__, __LINE__ + 1
20
+ @name = #{default_name.inspect}
21
+
22
+ # Theme name
23
+ #
24
+ # @return [Symbol]
8
25
  def name
9
26
  @name || raise("Theme name is no defined")
10
27
  end
11
28
 
12
- @path = nil
13
- def path
14
- @path || raise("Theme path is no defined")
29
+ @root_path = #{default_root.inspect}
30
+
31
+ # Theme project's root path
32
+ #
33
+ # @return [String]
34
+ def root_path
35
+ @root_path || raise("Theme project's root path is no defined")
36
+ end
37
+
38
+ # Theme's relative path, 'theme' by default
39
+ #
40
+ # @return [String] default is 'theme'
41
+ def theme_path
42
+ @theme_path || 'theme'
15
43
  end
16
44
 
17
- private
45
+ protected
18
46
 
47
+ # Set theme name
48
+ #
49
+ # @param [String] name
50
+ # @return [Symbol] symbolized name
19
51
  def set_name(name)
20
52
  @name = name.to_sym
21
53
  end
22
54
 
23
- def set_path(path)
24
- @path = path
55
+ # Set root path of theme project
56
+ #
57
+ # @param [String] path
58
+ # @return [String]
59
+ def set_root_path(path)
60
+ @root_path = path
61
+ end
62
+
63
+ # Set theme's relative path, which path includes assets and views
64
+ #
65
+ # @param [String] path is a relative path where assets and views locate.
66
+ # @return [String]
67
+ def set_theme_path(path)
68
+ @theme_path = theme_path
25
69
  end
26
70
 
27
71
  RUBY
@@ -1,3 +1,3 @@
1
1
  module Themeable
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -3,6 +3,7 @@ require 'theme_<%= theme_name %>/version'
3
3
 
4
4
  module <%= app_name.camelize %>
5
5
  include Themeable::Theme
6
- set_name '<%= theme_name %>'
7
- set_path File.expand_path('../../theme', __FILE__)
6
+ # set_name '<%= theme_name %>' # by default, resovle name by file path automatically
7
+ # set_root_path File.expand_path('../..', __FILE__)
8
+ # set_theme_path 'theme'
8
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: themeable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - xiaohui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-06 00:00:00.000000000 Z
11
+ date: 2016-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails