Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

catalog.themes now only returns valid theme installations, ignoring e…

…mpty or non-git directories. updated interfacelift 'list' command to work with new catalog class. improved test cases on catalog.themes and has_theme(theme)
  • Loading branch information...
commit 40a594eb1c03e92577bb523d555021b80aae7720 1 parent 1ff8dba
Jeroen van Schagen authored
Showing with 31 additions and 31 deletions.
  1. +20 −19 bin/interfacelift
  2. +2 −2 lib/catalog.rb
  3. +9 −10 spec/catalog_spec.rb
View
39 bin/interfacelift
@@ -9,6 +9,7 @@ program :name, 'interfacelift'
program :version, InterfaceLift::VERSION
program :description, 'Installs layouts in rails apps'
+# Install
command :install do |c|
c.syntax = 'install theme path'
c.description = 'installs theme in rails app'
@@ -19,19 +20,17 @@ command :install do |c|
else
begin
theme = args[0]
- path = args[1].nil? ? "." : args[1]
- catalog = InterfaceLift::Catalog.new
-
- raise "You need to provide the git repo of #{theme}, using the --repo flag" if options.repo.nil?
+ path = args[1].nil? ? "." : args[1]
- if catalog.theme_exists?(theme)
- puts "Fetching updates for #{theme}..."
- catalog.update_theme(theme)
- else
+ # Retrieve theme and store in catalog
+ catalog = InterfaceLift::Catalog.new
+ if ! catalog.theme_exists?(theme)
+ raise "You need to provide the git repo of #{theme}, using the --repo flag" if options.repo.nil?
puts "Fetching theme #{theme}..."
- catalog.add_theme(theme,options.repo)
+ catalog.add_theme(theme,options.repo)
end
-
+
+ # Transfer theme from catalog in rails app
installer = InterfaceLift::Installer.new(path,theme)
installer.install!
rescue Exception => e
@@ -42,16 +41,18 @@ command :install do |c|
end
end
+# List
command :list do |c|
c.syntax = 'list'
c.description = 'shows a list of all available themes'
- c.action do |args, options|
- begin
- manager = InterfaceLift::ThemeManager.new
- manager.available_themes
- rescue Exception => e
- puts e
- end
+ c.action do |args, options|
+ catalog = InterfaceLift::Catalog.new
+ themes = catalog.themes
+ if themes.size == 0
+ puts "No themes installed, use 'install' or 'add'"
+ else
+ puts "Available themes:"
+ catalog.themes.each { |theme| puts theme }
+ end
end
-end
-
+end
View
4 lib/catalog.rb
@@ -14,14 +14,14 @@ def initialize(catalog_path = nil)
def themes
themes = []
Dir.glob("#{@catalog_path}/*").each do |item|
- themes << item if File.directory? item
+ themes << item if git_repo?(item)
end
themes.map { |path| path.split("/").last }
end
# Does the given theme exist in the working path
def theme_exists?(theme)
- themes.include?(theme) && git_repo?(theme)
+ themes.include?(theme)
end
# Is the argumented theme a git repository?
View
19 spec/catalog_spec.rb
@@ -26,21 +26,20 @@
end
it "should provide a list of the available themes in the given path" do
- themes = ["test_theme", "test_theme2", "bright_admin"]
- @cat.themes.sort == themes.sort
- # (@cat.themes + (themes)).uniq.size.should == 3
+ themes = ["test_theme", "test_theme2"]
+ paths = themes.map { |path| "#{@cat.catalog_path}/#{path}" }
+ Dir.stubs(:glob).with("#{@cat.catalog_path}/*").returns(paths)
+ paths.each { |path| @cat.expects(:git_repo?).with(path).returns(true) }
+ @cat.themes.sort.should == themes.sort
end
-
- it "should check if a theme exists" do
- @cat.expects(:git_repo?).with("test_theme2").returns(true)
- @cat.theme_exists?("test_theme2").should == true
- @cat.theme_exists?("test_theme3").should == false
+ it "should check if a theme exists" do
+ @cat.stubs(:themes).returns("test_theme")
+ @cat.theme_exists?("test_theme").should == true
+ @cat.theme_exists?("test_theme2").should == false
end
-
context "Updating a theme from a git repo" do
-
before(:each) do
@git_mock = mock('Git',:index => mock("index",:readable? => true))
Git.stubs(:open).returns(@git_mock)
Please sign in to comment.
Something went wrong with that request. Please try again.