theme_generator 1.1.1 → 1.2.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.
data/USAGE CHANGED
@@ -3,7 +3,7 @@ NAME
3
3
  folder structure.
4
4
 
5
5
  SYNOPSIS
6
- theme [theme name]
6
+ theme [theme name] (use _system_ to update theme system files only)
7
7
 
8
8
  DESCRIPTION
9
9
  This generator creates general purpose theme support. It's designed to leverage
@@ -12,10 +12,18 @@ DESCRIPTION
12
12
 
13
13
  Included:
14
14
  - Abstraction of Typo style theme support
15
- - New View Tag Helpers for accessing themed content
15
+ - Tag helpers for accessing theme specfic content
16
+ - Support for overriding views in theme
17
+ - Support for ERb templates and Liquid templates
18
+ - Theme system can allow a mix of both template types, or Liquid templates only
19
+ - Liquid tag for accessing theme specfic content
16
20
 
17
21
  EXAMPLE
18
- ./script/generate theme default
22
+ ./script/generate theme default
19
23
 
20
24
  This will generate the file structure for a theme named 'default' and prepare
21
25
  the rails application for theme support.
26
+
27
+ Starting with version 1.2, you can update just the theme system files by running:
28
+
29
+ ./script/generate theme _system_
data/templates/README CHANGED
@@ -35,26 +35,73 @@ In the views, there are theme specific helper tags available to you.
35
35
  - theme_stylesheet_link_tag
36
36
  - theme_stylesheet_path
37
37
 
38
+ Views can be overidden by placing templates in the themes/[theme_name]/views
39
+ folder. You can use the default ERb templates, or Liquid templates.
40
+
41
+ You can tell the theme system to only allow Liquid templates in a theme by
42
+ setting 'force_liquid' in your controller:
43
+
44
+ class ApplicationController < ActionController::Base
45
+
46
+ layout 'default'
47
+ theme 'blue'
48
+
49
+ force_liquid true
50
+
51
+ end
52
+
53
+ If force_liquid is set to true, the theme system will only render .liquid
54
+ template files. If .rhtml templates are found, an exception is raised.
55
+
56
+ Note: force_liquid is only for theme templates. Your
57
+ application templates can still be ERb (.rhtml)
58
+ files.
59
+
38
60
  Before hosting, I would recommend running the rake task to pre-cache all of
39
61
  the theme files:
40
62
 
41
- rake create_theme_cache
63
+ rake theme_create_cache
42
64
 
43
65
  There is also a handy rake task for removing all the cached theme files:
44
66
 
45
- rake remove_theme_cache
67
+ rake theme_remove_cache
68
+
69
+ You can also update the cache:
70
+
71
+ rake theme_update_cache
72
+
73
+ == Upgrading
74
+
75
+ Starting with version 1.2, you can update just the theme system files by
76
+ running:
77
+
78
+ ./script/generate theme _system_
46
79
 
47
80
 
48
81
  == Changelog
49
82
 
50
- 1.0.0 - Initial release
51
- 1.0.1 - Added 'themes' directory, theme definition file, and symlinks
52
- to the appropriate directories on supported platforms.
53
- 1.0.2 - The current_theme is now retrieved from the controller. Where
54
- symlinks are created on *nix systems, shortcuts are created
55
- on Windows if Win32Utils is installed.
83
+ 1.2.0 - Updated actionview_ex with the new render_file additions from
84
+ Typo. Renamed the rake tasks so that they all start with
85
+ 'theme' (theme_create_cache, theme_remove_cache,
86
+ theme_update_cache). You can update the system files by running:
87
+
88
+ $ ./script/generate theme _system_
89
+
90
+ Full support for Liquid templates, as well as an option to only
91
+ allow Liquid templates in a theme.
92
+
93
+ 1.1.1 - Added rake tasks for pre-caching the themes, and removing the
94
+ cached themes.
95
+
56
96
  1.1.0 - [Breaking] Abstraction of the Typo theme system. The themes are
57
97
  now the same as is used in Typo. The theme engine itself is a
58
98
  combination of plugins and a component.
59
- 1.1.1 - Added rake tasks for pre-caching the themes, and removing the
60
- cached themes.
99
+
100
+ 1.0.2 - The current_theme is now retrieved from the controller. Where
101
+ symlinks are created on *nix systems, shortcuts are created
102
+ on Windows if Win32Utils is installed.
103
+
104
+ 1.0.1 - Added 'themes' directory, theme definition file, and symlinks
105
+ to the appropriate directories on supported platforms.
106
+
107
+ 1.0.0 - Initial release
@@ -3,42 +3,41 @@
3
3
  ActionController::Base.class_eval do
4
4
 
5
5
  attr_accessor :current_theme
6
-
6
+ attr_accessor :force_liquid_template
7
+
7
8
  def self.theme(theme_name, conditions = {})
8
9
  # TODO: Allow conditions... (?)
9
10
  write_inheritable_attribute "theme", theme_name
10
11
  end
11
12
 
13
+ def self.force_liquid(force_liquid_value, conditions = {})
14
+ # TODO: Allow conditions... (?)
15
+ write_inheritable_attribute "force_liquid", force_liquid_value
16
+ end
17
+
18
+
12
19
  # You need to override this in your +ApplicationController+
13
20
  # This should return the current theme name
14
21
  def current_theme(passed_theme=nil)
15
22
  theme = passed_theme || self.class.read_inheritable_attribute("theme")
16
23
 
17
- active_theme = case theme
24
+ @active_theme = case theme
18
25
  when Symbol then send(theme)
19
26
  when Proc then theme.call(self)
20
27
  when String then theme
21
28
  end
22
29
  end
23
-
24
- private
25
-
26
- alias_method :__active_layout, :active_layout
27
-
28
- def active_layout(passed_layout = nil)
29
- unless current_theme.nil?
30
- puts "THEME LAYOUT"
31
- layout = passed_layout || self.class.read_inheritable_attribute("layout")
32
-
33
- active_layout = case layout
34
- when Symbol then send(layout)
35
- when Proc then layout.call(self)
36
- when String then layout
37
- end
38
-
39
- active_layout.include?("/") ? active_layout : Theme.new(current_theme).layout(active_layout) if active_layout
40
- else
41
- __active_layout(passed_layout)
30
+
31
+ def force_liquid_template(passed_value=nil)
32
+ force_liquid = passed_value || self.class.read_inheritable_attribute("force_liquid")
33
+
34
+ force_liquid_template = case force_liquid
35
+ when Symbol then send(force_liquid)
36
+ when Proc then force_liquid.call(self)
37
+ when String then force_liquid == 'true'
38
+ when TrueClass then force_liquid
39
+ when FalseClass then force_liquid
40
+ when Fixnum then force_liquid == 1
42
41
  end
43
42
  end
44
43
 
@@ -1,21 +1,46 @@
1
+ # Extend the Base ActionView to support rendering themes
2
+ #
1
3
  module ActionView
2
- class Base
3
- alias_method :__render_file, :render_file
4
-
5
- def render_file(template_path, use_full_path = true, local_assigns = {})
6
- if use_full_path
7
- begin
8
- theme_path = "../../themes/#{controller.current_theme}/views/#{template_path}"
9
- template_extension = pick_template_extension(theme_path)
10
- __render_file(theme_path, use_full_path, local_assigns)
11
- rescue => err
12
- __render_file(template_path, use_full_path, local_assigns)
13
- end
14
- else
15
- __render_file(template_path, use_full_path, local_assigns)
4
+ class ThemeError < StandardError
5
+ end
6
+
7
+ class Base
8
+ alias_method :__render_file, :render_file
9
+
10
+ def render_file(template_path, use_full_path = true, local_assigns = {})
11
+ search_path = [
12
+ "../themes/#{controller.current_theme}/views", # for components
13
+ "../../themes/#{controller.current_theme}/views", # for normal views
14
+ "../../themes/#{controller.current_theme}", # for layouts
15
+ "." # fallback
16
+ ]
17
+
18
+ if use_full_path
19
+ search_path.each do |prefix|
20
+ theme_path = prefix +'/'+ template_path
21
+ begin
22
+ template_extension = pick_template_extension(theme_path)
23
+
24
+ # Prevent .rhtml (or any other template type) if force_liquid == true
25
+ if controller.force_liquid_template and
26
+ template_extension.to_s != 'liquid' and
27
+ prefix != '.'
28
+ raise ThemeError.new("Template '#{template_path}' must be a liquid document")
29
+ end
30
+
31
+ local_assigns['active_theme'] = controller.current_theme unless controller.current_theme.nil?
32
+ rescue ActionView::ActionViewError => err
33
+ next
34
+ rescue ThemeError => err
35
+ # Should it raise an exception, or just call 'next' and revert to
36
+ # the default template?
37
+ raise err
38
+ end
39
+ return __render_file(theme_path, use_full_path, local_assigns)
40
+ end
41
+ else
42
+ __render_file(template_path, use_full_path, local_assigns)
43
+ end
16
44
  end
17
- end
18
- end
19
-
20
-
45
+ end
21
46
  end
data/templates/init.rb CHANGED
@@ -3,4 +3,11 @@ require 'actioncontroller_ex'
3
3
  require 'routeset_ex'
4
4
  require 'theme_helpers'
5
5
 
6
+ begin
7
+ require 'liquid_helpers'
8
+ rescue
9
+ # I guess Liquid isn't being used...
10
+ puts "Liquid helpers weren't loaded: #{$!}"
11
+ end
12
+
6
13
  ActionController::Routing::Routes.install_theme_routes
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html>
4
+ <head>
5
+ <title></title>
6
+ <link href="{% themeitem %} <%= file_name %> {% endthemeitem %}" media="screen" rel="Stylesheet" type="text/css" />
7
+ </head>
8
+ <body>
9
+ {{ content_for_layout }}
10
+ </body>
11
+ </html>
@@ -0,0 +1,45 @@
1
+ # A Liquid Tag for retrieving path information for theme specific media
2
+ #
3
+ # Returns the path based on the file extension
4
+ #
5
+ class Themeitem < Liquid::Block
6
+
7
+ @@image_exts = %w( .png .jpg .jpeg .jpe .gif )
8
+
9
+ @@stylesheet_exts = %w( .css )
10
+
11
+ @@javascript_exts = %w( .js .htc )
12
+
13
+ def initialize(markup, tokens)
14
+ super
15
+ #@media_type = markup.strip
16
+ end
17
+
18
+ def block_delimiter
19
+ ["endthemeitem"]
20
+ end
21
+
22
+ def block_name
23
+ "themeitem"
24
+ end
25
+
26
+ def render(context)
27
+ # Which, if either, of these are correct?
28
+ base_url = context['request'].relative_url_root || ActionController::Base.asset_host.to_s
29
+
30
+ filename = @nodelist.join('').strip
31
+ ext = File.extname( filename )
32
+
33
+ if @@image_exts.include?( ext )
34
+ "#{base_url}/themes/#{context['active_theme']}/images/#{filename}"
35
+
36
+ elsif @@stylesheet_exts.include?( ext )
37
+ "#{base_url}/themes/#{context['active_theme']}/stylesheets/#{filename}"
38
+
39
+ elsif @@javascript_exts.include?( ext )
40
+ "#{base_url}/themes/#{context['active_theme']}/javascripts/#{filename}"
41
+ end
42
+ end
43
+ end
44
+
45
+ Liquid::Template.register_block( 'themeitem', Themeitem )
data/templates/theme.rb CHANGED
@@ -8,11 +8,7 @@ class Theme
8
8
  @name = name
9
9
  @path = path ||= Theme.path_to_theme(name)
10
10
  end
11
-
12
- def layout(layout='default')
13
- "../../themes/#{name}/layouts/#{layout}"
14
- end
15
-
11
+
16
12
  def description
17
13
  File.read("#{path}/about.markdown") rescue "### #{name}"
18
14
  end
@@ -20,17 +16,6 @@ class Theme
20
16
  def self.themes_root
21
17
  RAILS_ROOT + "/themes"
22
18
  end
23
-
24
- # DEPRECATED: There is no 'current' theme, at least, not from here...
25
- def self.current_theme_path
26
- raise 'DEPRECATED: The current theme is set in the controller'
27
- "#{themes_root}/#{config[:theme]}"
28
- end
29
- # DEPRECATED: There is no 'current' theme, at least, not from here...
30
- def self.current
31
- theme_from_path(current_theme_path)
32
- end
33
-
34
19
 
35
20
  def self.path_to_theme(theme)
36
21
  "#{themes_root}/#{theme}"
@@ -1,6 +1,6 @@
1
1
 
2
2
  desc "Creates the cached (public) theme folders"
3
- task :create_theme_cache do
3
+ task :theme_create_cache do
4
4
  for theme in Dir.glob("#{RAILS_ROOT}/themes/*")
5
5
  theme_name = theme.split( File::Separator )[-1]
6
6
  puts "Creating #{RAILS_ROOT}/public/themes/#{theme_name}"
@@ -15,7 +15,11 @@ task :create_theme_cache do
15
15
  end
16
16
 
17
17
  desc "Removes the cached (public) theme folders"
18
- task :remove_theme_cache do
18
+ task :theme_remove_cache do
19
+ puts "Creating #{RAILS_ROOT}/public/themes/#{theme_name}"
19
20
  FileUtils.rm_r Dir.glob("#{RAILS_ROOT}/public/themes/*")
20
21
  FileUtils.rm_r "#{RAILS_ROOT}/public/themes", :force => true
21
22
  end
23
+
24
+ desc "Updates the cached (public) theme folders"
25
+ task :theme_update_cache => [:theme_remove_cache, :theme_create_cache]
data/theme_generator.rb CHANGED
@@ -1,23 +1,30 @@
1
1
  class ThemeGenerator < Rails::Generator::NamedBase
2
+
2
3
  def manifest
3
4
  record do |m|
4
- # Readme file
5
- m.template 'README', "README_THEMES"
6
5
 
7
- # Theme folder(s)
8
- m.directory File.join( "themes", file_name )
9
- m.template 'about.markdown', File.join( 'themes', file_name, 'about.markdown' )
10
- m.template 'preview.png', File.join( 'themes', file_name, 'preview.png' )
6
+ if file_name != '_system_'
7
+
8
+ # Theme folder(s)
9
+ m.directory File.join( "themes", file_name )
10
+ m.template 'about.markdown', File.join( 'themes', file_name, 'about.markdown' )
11
+ m.template 'preview.png', File.join( 'themes', file_name, 'preview.png' )
11
12
 
12
- m.directory File.join( "themes", file_name, "stylesheets" )
13
- m.template "theme.css", File.join( "themes", file_name, "stylesheets", "#{file_name}.css" )
13
+ m.directory File.join( "themes", file_name, "stylesheets" )
14
+ m.template "theme.css", File.join( "themes", file_name, "stylesheets", "#{file_name}.css" )
15
+
16
+ m.directory File.join( "themes", file_name, "layouts" )
17
+ m.template 'layout.rhtml', File.join( 'themes', file_name, 'layouts', 'default.rhtml' )
18
+ m.template 'layout.liquid', File.join( 'themes', file_name, 'layouts', 'default.liquid' )
14
19
 
15
- m.directory File.join( "themes", file_name, "layouts" )
16
- m.template 'layout.rhtml', File.join( 'themes', file_name, 'layouts', 'default.rhtml' )
20
+ m.directory File.join( "themes", file_name, "views" )
21
+ m.directory File.join( "themes", file_name, "images" )
22
+ m.directory File.join( "themes", file_name, "javascript" )
23
+
24
+ end
17
25
 
18
- m.directory File.join( "themes", file_name, "views" )
19
- m.directory File.join( "themes", file_name, "images" )
20
- m.directory File.join( "themes", file_name, "javascript" )
26
+ # Readme file
27
+ m.template 'README', "README_THEMES"
21
28
 
22
29
  # The ThemeEngine plugins
23
30
  m.directory File.join( "vendor", "plugins", "theme_engine" )
@@ -25,6 +32,7 @@ class ThemeGenerator < Rails::Generator::NamedBase
25
32
  m.directory File.join( "vendor", "plugins", "theme_engine", "lib" )
26
33
  m.template 'actioncontroller_ex.rb', File.join( 'vendor', 'plugins', 'theme_engine', 'lib', 'actioncontroller_ex.rb' )
27
34
  m.template 'actionview_ex.rb', File.join( 'vendor', 'plugins', 'theme_engine', 'lib', 'actionview_ex.rb' )
35
+ m.template 'liquid_helpers.rb', File.join( 'vendor', 'plugins', 'theme_engine', 'lib', 'liquid_helpers.rb' )
28
36
  m.template 'routeset_ex.rb', File.join( 'vendor', 'plugins', 'theme_engine', 'lib', 'routeset_ex.rb' )
29
37
  m.template 'theme_helpers.rb', File.join( 'vendor', 'plugins', 'theme_engine', 'lib', 'theme_helpers.rb' )
30
38
  m.directory File.join( "vendor", "plugins", "theme_engine", "tasks" )
@@ -34,6 +42,7 @@ class ThemeGenerator < Rails::Generator::NamedBase
34
42
  m.directory File.join( "components", "theme_system" )
35
43
  m.template 'theme.rb', File.join( 'components', 'theme_system', 'theme.rb' )
36
44
  m.template 'theme_controller.rb', File.join( 'components', 'theme_system', 'theme_controller.rb' )
45
+
37
46
  end
38
47
  end
39
48
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: theme_generator
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.1
7
- date: 2005-11-01 00:00:00 -06:00
6
+ version: 1.2.0
7
+ date: 2005-11-11 00:00:00 -06:00
8
8
  summary: "[Rails] Theme generator adds support for themes into Rails applications"
9
9
  require_paths:
10
10
  - lib
@@ -39,6 +39,8 @@ files:
39
39
  - templates/theme_controller.rb
40
40
  - templates/actioncontroller_ex.rb
41
41
  - templates/layout.rhtml
42
+ - templates/layout.liquid
43
+ - templates/liquid_helpers.rb
42
44
  - templates/theme.css
43
45
  - templates/theme_helpers.rb
44
46
  - templates/themes.rake