aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/initializers/alaveteli.rb1
-rw-r--r--config/initializers/theme_loader.rb3
-rw-r--r--lib/tasks/themes.rake2
-rw-r--r--lib/theme.rb3
-rw-r--r--spec/lib/theme_spec.rb25
5 files changed, 31 insertions, 3 deletions
diff --git a/config/initializers/alaveteli.rb b/config/initializers/alaveteli.rb
index 8ae78c80c..685ddebb8 100644
--- a/config/initializers/alaveteli.rb
+++ b/config/initializers/alaveteli.rb
@@ -50,6 +50,7 @@ require 'normalize_string'
require 'alaveteli_file_types'
require 'alaveteli_localization'
require 'message_prominence'
+require 'theme'
AlaveteliLocalization.set_locales(AlaveteliConfiguration::available_locales,
AlaveteliConfiguration::default_locale)
diff --git a/config/initializers/theme_loader.rb b/config/initializers/theme_loader.rb
index 1ad2d01f1..b3ae11e1e 100644
--- a/config/initializers/theme_loader.rb
+++ b/config/initializers/theme_loader.rb
@@ -18,7 +18,6 @@ if Rails.env == "test"
end
else
for url in AlaveteliConfiguration::theme_urls.reverse
- theme_name = url.sub(/.*\/(.*).git/, "\\1")
- require_theme(theme_name)
+ require_theme theme_url_to_theme_name(url)
end
end
diff --git a/lib/tasks/themes.rake b/lib/tasks/themes.rake
index a8d16f108..1eed92f1e 100644
--- a/lib/tasks/themes.rake
+++ b/lib/tasks/themes.rake
@@ -85,7 +85,7 @@ namespace :themes do
def install_theme(theme_url, verbose, deprecated=false)
deprecation_string = deprecated ? " using deprecated THEME_URL" : ""
- theme_name = File.basename(theme_url, '.git')
+ theme_name = theme_url_to_theme_name theme_url
puts "Installing theme #{theme_name}#{deprecation_string} from #{theme_url}"
uninstall(theme_name, verbose) if installed?(theme_name)
install_theme_using_git(theme_name, theme_url, verbose)
diff --git a/lib/theme.rb b/lib/theme.rb
new file mode 100644
index 000000000..4f03b5d99
--- /dev/null
+++ b/lib/theme.rb
@@ -0,0 +1,3 @@
+def theme_url_to_theme_name(theme_url)
+ File.basename theme_url, '.git'
+end
diff --git a/spec/lib/theme_spec.rb b/spec/lib/theme_spec.rb
new file mode 100644
index 000000000..829c1a269
--- /dev/null
+++ b/spec/lib/theme_spec.rb
@@ -0,0 +1,25 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe "theme_url_to_theme_name" do
+
+ it "should deal with a typical bare repo URL" do
+ url = 'git://wherever/blah-theme.git'
+ theme_url_to_theme_name(url).should == 'blah-theme'
+ end
+
+ it "should deal with a typical bare repo URL with trailing slashes" do
+ url = 'ssh://wherever/blah-theme.git//'
+ theme_url_to_theme_name(url).should == 'blah-theme'
+ end
+
+ it "should deal with a typical non-bare repo URL" do
+ url = '/home/whoever/themes/blah-theme'
+ theme_url_to_theme_name(url).should == 'blah-theme'
+ end
+
+ it "should deal with a typical non-bare repo URL with a trailing slash" do
+ url = '/home/whoever/themes/blah-theme/'
+ theme_url_to_theme_name(url).should == 'blah-theme'
+ end
+
+end