Permalink
Browse files

Make some default settings in configuration

  • Loading branch information...
1 parent 4ced6cf commit 49d88a60e403d766acc22d838f157171f1468f73 @zires committed Mar 15, 2012
View
@@ -1,4 +1,4 @@
-#source "http://ruby.taobao.org" # For china
-source "source http://rubygems.org"
+source "http://ruby.taobao.org" # For china
+#source "http://rubygems.org"
gemspec
View
@@ -1,3 +1,10 @@
+PATH
+ remote: .
+ specs:
+ theme_park (0.1.0.beta)
+ activesupport (>= 3.1)
+ rack
+
GEM
remote: http://ruby.taobao.org/
specs:
@@ -36,7 +43,7 @@ GEM
i18n (0.6.0)
journey (1.0.3)
json (1.6.5)
- mail (2.4.3)
+ mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
@@ -69,10 +76,6 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
- simplecov (0.6.1)
- multi_json (~> 1.0)
- simplecov-html (~> 0.5.3)
- simplecov-html (0.5.3)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
@@ -92,12 +95,10 @@ PLATFORMS
ruby
DEPENDENCIES
- activesupport (>= 3.1)
bundler (~> 1.0.0)
minitest
- rack
rails (>= 3.1)
- simplecov (~> 0.6.1)
sqlite3
+ theme_park!
turn
yard (~> 0.7)
@@ -11,16 +11,17 @@
# |- views
# |- layouts
#
-# Change below lines if you really need to.
+# Uncomment below lines if you really need to.
# ===
-ThemePark.setup do |config|
+# ThemePark.setup do |config|
+#
+# config.root = '/themes'
+# config.prefix = 'themes'
+# config.images_path = ':root/:name/assets/images'
+# config.javascripts_path = ':root/:name/assets/javascripts'
+# config.stylesheets_path = ':root/:name/assets/stylesheets'
+# config.compiled_path = ':root/:name/assets/compiled'
+# config.views_path = ':root/:name/views'
- config.root = "#{::Rails.root}/themes/"
- config.prefix = 'themes'
- config.images_path = ':root/:name/assets/images'
- config.javascripts_path = ':root/:name/assets/javascripts'
- config.stylesheets_path = ':root/:name/assets/stylesheets'
- config.compiled_path = ':root/:name/assets/compiled'
- config.views_path = ':root/:name/views'
-
-end
+# end
+# ===
View
@@ -34,7 +34,7 @@ def self.setup
class << self
- delegate :root, :prefix, :to => :config
+ delegate :base, :root, :base_root, :prefix, :to => :config
def config
@@config ||= ThemePark::Configuration.new
@@ -46,15 +46,15 @@ def version
# Return the path of given theme name.
def path(theme_name)
- File.join root, theme_name
+ File.join base_root, theme_name
end
def exist?(theme_name)
Dir.exist? path(theme_name)
end
def interpolate(pattern, theme_name)
- pattern.gsub(":root", ThemePark.root).gsub(":name", theme_name.to_s)
+ pattern.gsub(":root", base_root).gsub(":name", theme_name.to_s)
end
##
@@ -110,7 +110,7 @@ def theme_assets_path(theme_name)
# The assets path contains all themes' images, javascripts and stylesheets path.
def assets_path
- Dir.glob( File.join(self.root, "*") ).map do |theme_name|
+ Dir.glob( File.join(self.base_root, "*") ).map do |theme_name|
theme_name = File.basename(theme_name)
theme_assets_path(theme_name)
end.flatten
@@ -3,20 +3,40 @@ module ThemePark
class Configuration
- # It is the root path for putting theme folders.
- # In rails application, usual is "#{Rails.root}/themes/".
+ # It is the base path for putting themes folder.
+ # For example in rails application is:
+ # ===
+ # Rails.root
+ attr_accessor :base
+
+ # It is the root path for putting each theme folder.
+ # usual is:
+ # ===
+ # /themes
attr_accessor :root
-
- def root
- @root.chomp('/')
- end
# The prefix is used to mount route.
attr_accessor :prefix
# The place contains images, javascripts, stylesheets, compiled files and view files.
attr_accessor :images_path, :javascripts_path, :stylesheets_path, :compiled_path, :views_path
+ def initialize
+ # Default settings
+ @base = ''
+ @root = '/themes'
+ @prefix = 'themes'
+ @images_path = ':root/:name/assets/images'
+ @javascripts_path = ':root/:name/assets/javascripts'
+ @stylesheets_path = ':root/:name/assets/stylesheets'
+ @compiled_path = ':root/:name/assets/compiled'
+ @views_path = ':root/:name/views'
+ end
+
+ def base_root
+ File.join(base, root).chomp('/')
+ end
+
end
end
@@ -17,7 +17,9 @@ class Railtie < ::Rails::Railtie
# Because this is boot after initializer file.
# So config/initializers/theme_park.rb must exist.
- config.theme_park = ThemePark
+ config.theme_park = ThemePark.setup do |config|
+ config.base = ::Rails.root
+ end
ActiveSupport.on_load(:action_view) do
ActionView::Helpers::AssetTagHelper.send :include, ThemePark::Rails::AssetTagHelper
@@ -0,0 +1 @@
+<h1>theme_park</h1>
View
@@ -21,13 +21,6 @@
rescue LoadError
end
-# Require rails
-begin
- require 'rails'
-rescue Exception => e
- puts "=== Test environment need rails version above 3.1 ==="
-end
-
require File.expand_path("../dummy/config/environment.rb", __FILE__)
require "rails/test_help"
View
@@ -6,7 +6,7 @@ class RailtieTest < ActiveSupport::TestCase
theme_park = Dummy::Application.config.theme_park
assert_equal(ThemePark, theme_park)
assert_equal('themes', theme_park.prefix)
- assert_equal("#{Dummy::Application.root}/themes", theme_park.root)
+ assert_equal("#{Dummy::Application.root}/themes", theme_park.base_root)
end
test 'action_view should load ThemePark::Rails::ActionView' do
View
@@ -5,21 +5,20 @@ class ThemeParkTest < MiniTest::Unit::TestCase
def setup
@logic_path = File.dirname(__FILE__)
ThemePark.setup do |config|
- config.root = "#{@logic_path}/themes/"
- config.prefix = 'themes'
- config.images_path = ':root/:name/assets/images'
- config.javascripts_path = ':root/:name/assets/javascripts'
- config.stylesheets_path = ':root/:name/assets/stylesheets'
- config.compiled_path = ':root/:name/assets/compiled'
- config.views_path = ':root/:name/views'
+ config.base = @logic_path
end
end
def teardown
end
def test_root
- assert_equal("#{@logic_path}/themes", ThemePark.root)
+ # default setting
+ assert_equal("/themes", ThemePark.root)
+ end
+
+ def test_base_root
+ assert_equal("#{@logic_path}/themes", ThemePark.base_root)
end
def test_prefix
No changes.
No changes.
View
@@ -29,5 +29,6 @@ Gem::Specification.new do |s|
s.add_development_dependency "bundler", "~> 1.0.0"
s.add_development_dependency "minitest"
s.add_development_dependency "turn"
+ s.add_development_dependency "rails", ">= 3.1"
end

0 comments on commit 49d88a6

Please sign in to comment.