diff --git a/lib/themes_for_rails.rb b/lib/themes_for_rails.rb index 5345801..105fe3d 100644 --- a/lib/themes_for_rails.rb +++ b/lib/themes_for_rails.rb @@ -19,7 +19,8 @@ def config end def available_themes(&block) - Dir.glob(File.join(config.themes_path, "*"), &block) + #Dir.glob(File.join(config.themes_path, "*"), &block) + Dir.glob(File.join(config.themes_dir, "*"), &block) end alias each_theme_dir available_themes diff --git a/lib/themes_for_rails/common_methods.rb b/lib/themes_for_rails/common_methods.rb index 722dd5b..49e429f 100644 --- a/lib/themes_for_rails/common_methods.rb +++ b/lib/themes_for_rails/common_methods.rb @@ -1,9 +1,5 @@ module ThemesForRails module CommonMethods - def view_path_for(theme) - File.join(theme_path_for(theme), "views") - end - def theme_name @cached_theme_name ||= begin case @theme_name @@ -25,45 +21,29 @@ def set_theme(name) if valid_theme? add_theme_view_path + add_theme_assets_path end end - public + protected + # Check theme is valid def valid_theme? !self.theme_name.nil? end - # will add the view path for the current theme + # Add view path for current theme def add_theme_view_path - add_assets_path_for(self.theme_name) - add_theme_view_path_for(self.theme_name) + self.view_paths.insert 0, ActionView::FileSystemResolver.new("#{ThemesForRails.config.themes_dir}/#{self.theme_name}/views") end - # will add the view path for a given theme name - def add_theme_view_path_for(name) - self.view_paths.insert 0, ActionView::FileSystemResolver.new(view_path_for(name)) - end - - # Add paths for Sprockets - def add_assets_path_for(name) - assets_dir = File.join(ThemesForRails.config.base_dir, ThemesForRails.config.themes_dir, name, 'assets') + # Add assets path for current theme + def add_theme_assets_path + assets_dir = File.join(Rails.root.to_s, ThemesForRails.config.themes_dir, self.theme_name, 'assets') [:stylesheets, :javascripts, :images].each do |asset_type| Rails.application.assets.append_path(File.join(assets_dir, asset_type.to_s)) end end - - def public_theme_path - theme_path("/") - end - - def theme_path(base = ThemesForRails.config.base_dir) - theme_path_for(theme_name, base) - end - - def theme_path_for(name, base = ThemesForRails.config.base_dir, theme_dir = ThemesForRails.config.themes_dir) - File.join(base, theme_dir, name) - end end end \ No newline at end of file diff --git a/lib/themes_for_rails/config.rb b/lib/themes_for_rails/config.rb index ccf8480..095fe31 100644 --- a/lib/themes_for_rails/config.rb +++ b/lib/themes_for_rails/config.rb @@ -1,7 +1,6 @@ module ThemesForRails class Config - - attr_writer :base_dir, :themes_dir + attr_writer :themes_dir #:base_dir, #attr_accessor :use_sass def initialize(&block) @@ -9,29 +8,23 @@ def initialize(&block) yield if block_given? end - def base_dir - @base_dir ||= Rails.root - end + #def base_dir + # @base_dir ||= Rails.root + #end def themes_dir @themes_dir ||= "app/themes" + @themes_dir = File.join(Rails.root, @themes_dir) + @themes_dir end - def themes_path - File.join(base_dir, themes_dir) - end + #def themes_path + # File.join(Rails.root, themes_dir) + #end def clear - @base_dir = nil + #@base_dir = nil @themes_dir = nil end - - #def use_sass? - # @use_sass and sass_is_available? - #end - - #def sass_is_available? - # !!defined?(Sass::Plugin) - #end end end \ No newline at end of file diff --git a/spec/common_methods_spec.rb b/spec/common_methods_spec.rb index 4354e97..fcfac10 100644 --- a/spec/common_methods_spec.rb +++ b/spec/common_methods_spec.rb @@ -7,19 +7,4 @@ @common.theme_name = "awesome" ThemesForRails.config.clear end - - it 'should use config base_dir to build theme path' do - ThemesForRails.config.base_dir ='some_path' - @common.theme_path.should match(/some_path/) - end - - it 'should use config themes_dir to build theme path' do - ThemesForRails.config.themes_dir ='skinner' - @common.theme_path.should match(/skinner/) - end - - it 'should use config base_dir to build theme path for theme' do - ThemesForRails.config.base_dir ='some_path' - @common.theme_path_for('doodley').should match(/some_path/) - end end \ No newline at end of file diff --git a/spec/config_spec.rb b/spec/config_spec.rb index c0696db..f92b0e2 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -5,14 +5,6 @@ ThemesForRails.config.clear end - it "should change the base directory" do - ThemesForRails.config do |config| - config.base_dir = 'app/empty_themes' - end - - ThemesForRails.available_theme_names.should be_empty - end - it 'should change the directory to views' do ThemesForRails.config do |config| config.themes_dir = 'app/themes'