Permalink
Browse files

- Added Readme

- The binary is adjusted to work with the new catalog manager class.
- The Installer is adjusted to work with the new catalog manager class.
- Stuff is working now!
  • Loading branch information...
michel committed Nov 19, 2009
1 parent 6c5e75c commit 1071d5a37716a3db3a64189bb5dbbe5823ce48b9
Showing with 117 additions and 52 deletions.
  1. +57 −0 README.rdoc
  2. +4 −4 Rakefile
  3. +17 −2 bin/interfacelift
  4. +5 −7 lib/catalog.rb
  5. +4 −14 lib/installer.rb
  6. +1 −0 lib/interfacelift.rb
  7. +23 −20 spec/catalog_spec.rb
  8. +2 −5 spec/installer_spec.rb
  9. +4 −0 spec/interfacelift_spec.rb
View
@@ -0,0 +1,57 @@
+= WARNING! THIS GEM IS UNDER HEAVY DEVELOPMENT AND SHOULD BE USED WITH CAUTION!!!11
+
+= InterfaceLift
+* http://github.com/michel/interfaceLift
+
+== DESCRIPTION
+
+Are you a programmer? Do you hate doing GUI related stuff? Or just want your app to look good without much effort?
+Well interfacelift might be the gem your looking for!
+
+Interface lift is a handy gem for installing themes in rails apps.
+You can install themes with just one single command:
+
+ interfacelift install bright_admin --repo git://github.com/michel/bright_admin.git
+
+== FEATURES
+
+- Needs MOAR features..
+
+== SYNOPSIS
+
+ rails my_app
+ cd my_app
+ interfacelift install bright_admin --repo git://github.com/michel/bright_admin.git
+
+== INSTALL
+
+ sudo gem install interfacelift --source http://gemcutter.org
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2009 Michel de Graaf (michel@re-invention.nl), http://re-invention.nl
+Copyright (c) 2009 Jeroen van Schagen (jeroen.v.schagen@gmail.com)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+
View
@@ -1,6 +1,5 @@
require 'rubygems'
require 'rake'
-require 'spec/rake/spectask'
begin
@@ -30,9 +29,10 @@ end
desc "Run all specs with RCov"
Spec::Rake::SpecTask.new('specs_with_rcov') do |t|
- t.spec_files = FileList['spec/**/*.rb']
- t.rcov = true
- t.rcov_opts = ['--exclude', 'spec', 'spec']
+ t.spec_files = FileList['spec/*_spec.rb']
+ t.rcov = true
+ t.spec_opts = ['--options', "\"spec/spec.opts\""]
+ t.rcov_opts = ['--exclude', 'spec']
end
View
@@ -12,12 +12,27 @@ program :description, 'Installs layouts in rails apps'
command :install do |c|
c.syntax = 'install theme path'
c.description = 'installs theme in rails app'
+ c.option '--repo git://repo.git', String, 'Fetch the theme from a git repo'
c.action do |args, options|
if args.size < 1
- puts "You need to give the theme name and the path to the rails app"
+ puts "You need to give the theme name."
else
begin
- installer = InterfaceLift::Installer.new(args[1].nil? ? "." : args[1] ,args[0])
+ 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?
+
+ if catalog.theme_exists?(theme)
+ puts "Fetching updates for #{theme}..."
+ catalog.update_theme(theme)
+ else
+ puts "Fetching theme #{theme}..."
+ catalog.add_theme(theme,options.repo)
+ end
+
+ installer = InterfaceLift::Installer.new(path,theme)
installer.install!
rescue Exception => e
puts e
View
@@ -3,11 +3,10 @@
module InterfaceLift
class Catalog
- DEFAULT_CATELOG_PATH = "~/.interfacelift"
attr_reader :catalog_path
def initialize(catalog_path = nil)
- @catalog_path = catalog_path.nil? ? DEFAULT_CATELOG_PATH : catalog_path
+ @catalog_path = catalog_path.nil? ? ::InterfaceLift::DEFAULT_CATALOG_PATH : catalog_path
create_catalog_path!
end
@@ -22,7 +21,7 @@ def themes
# Does the given theme exist in the working path
def theme_exists?(theme)
- themes.include?(theme)
+ themes.include?(theme) && git_repo?(theme)
end
# Is the argumented theme a git repository?
@@ -32,8 +31,8 @@ def git_repo?(theme)
rescue ArgumentError => e
# If the path does not exist it will return an ArgumentError
return false
- end
- !g.repo.path.nil?
+ end
+ g.index.readable?
end
# Retrieve the latest version of argumented theme from git repository
@@ -45,15 +44,14 @@ def update_theme(theme)
# Remove theme from catalog
def remove_theme(theme)
- return false unless theme_exists?(theme)
FileUtils.rm_rf("#{@catalog_path}/#{theme}")
end
# Download a theme from git repository
# returns true when sucessfull
# raises exception when it fails
def add_theme(theme, repo)
- remove_theme(theme) if theme_exists?(theme)
+ remove_theme(theme)
!Git.clone(repo, "#{@catalog_path}/#{theme}").repo.path.nil?
end
View
@@ -1,14 +1,12 @@
module InterfaceLift
class Installer
attr_reader :path, :theme, :theme_path
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
- SHARED = "#{APP_ROOT}/lib/templates/shared"
- def initialize(path,theme)
+ def initialize(path,theme,catalog_path=InterfaceLift::DEFAULT_CATALOG_PATH)
@path = path
- @theme = theme
- @theme_path = "#{APP_ROOT}/lib/templates/#{theme}"
+ @theme = theme
+ @theme_path = "#{catalog_path}/#{theme}"
raise "Given path does not contain a rails app." unless File.directory? "#{@path}/public"
raise "Theme #{@theme} is not available." unless File.directory? @theme_path
@@ -19,7 +17,6 @@ def install!
install_stylesheets
install_layouts
install_javascript
- install_shared
theme_install
end
@@ -67,13 +64,6 @@ def install_javascript
end
FileUtils.cp_r "#{@theme_path}/public/javascripts","#{path}/public"
end
-
- def install_shared
- return nil unless File.directory? "#{SHARED}/icons"
- Dir.glob("#{SHARED}/icons/*").each do |file|
- puts "Installing icons/#{file.split("/").last}"
- end
- FileUtils.cp_r "#{SHARED}/icons","#{path}/public/images/"
- end
+
end
end
View
@@ -1,5 +1,6 @@
module InterfaceLift
VERSION = "0.0.1"
+ DEFAULT_CATALOG_PATH = "#{ENV["HOME"]}/.interfacelift"
end
$LOAD_PATH << File.expand_path(File.dirname(__FILE__))
require "catalog"
View
@@ -9,14 +9,14 @@
context "Initialize" do
it "should initialize with a path that contains the users current themes" do
- @path = "~/.interfacelift"
+ @path = "test_path"
@cat = Catalog.new(@path)
@cat.catalog_path.should == @path
end
it "should take a default path when no path is provided" do
@cat = Catalog.new
- @cat.catalog_path.should == Catalog::DEFAULT_CATELOG_PATH
+ @cat.catalog_path.should == ::InterfaceLift::DEFAULT_CATALOG_PATH
end
end
@@ -32,7 +32,8 @@
end
- it "should check if a theme exists" do
+ 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
end
@@ -41,7 +42,7 @@
context "Updating a theme from a git repo" do
before(:each) do
- @git_mock = mock('Git', :repo => mock("git", :path => "fakepath"))
+ @git_mock = mock('Git',:index => mock("index",:readable? => true))
Git.stubs(:open).returns(@git_mock)
end
@@ -56,13 +57,21 @@
end
end
-
- it "should check if the directory contains a git repo" do
- @git_mock = mock('Git', :repo => mock("git", :path => "fakepath"))
- Git.stubs(:open).returns(@git_mock)
- @cat.git_repo?("test_theme2").should == true
+
+ context "Checking if a directory contains a git repo" do
+ it "should return true if the directory contains a git repo" do
+ @git_mock = mock('Git',:index => mock("index",:readable? => true))
+ Git.stubs(:open).returns(@git_mock)
+ @cat.git_repo?("test_theme2").should == true
+ end
+
+
+ it "should return false if the directory contains a git repo" do
+ @cat.git_repo?("test_theme3").should == false
+ end
+
end
-
+
context "Download a theme from a git repo" do
it "should return an exception when given an invalid repository path" do
lambda { @cat.add_theme("mysweettheme", "git://fakepath.git") }.should raise_error Git::GitExecuteError
@@ -85,23 +94,17 @@
end
it "should return false when a theme doesn't exist in catalog" do
- @cat.stubs(:theme_exists?).returns(false)
- theme_name = "non_existing_theme"
- @cat.remove_theme(theme_name).should == false
+ theme_name = "non_existing_theme"
+ FileUtils.expects(:rm_rf).with("#{@cat.catalog_path}/#{theme_name}")
+ @cat.remove_theme(theme_name).should
end
end
- end
-
+ end
it "should create the catalog folder when it does not exists" do
non_existing_path = "no_path"
File.expects(:exists?).with(non_existing_path)
FileUtils.expects(:mkdir_p).with(non_existing_path)
@new_cat = Catalog.new(non_existing_path)
- #@new_cat.create_catalog_path!
end
-
-
-
-
end
View
@@ -5,7 +5,7 @@
before(:each) do
@path = "/tmp"
@theme = "test_theme"
- @theme_path = "#{GEM_ROOT}/lib/templates/#{@theme}"
+ @theme_path = "#{ENV['HOME']}/.interfacelift/#{@theme}"
end
def valid_arguments
@@ -65,10 +65,7 @@ def valid_arguments
it "Should copy over javascripts to the RAILS_ROOT/public folder" do
FileUtils.expects(:cp_r).with("#{@theme_path}/public/javascripts","#{@path}/public")
end
-
- it "Should copy over shared resources to the RAILS_ROOT/public folder" do
- FileUtils.expects(:cp_r).with("#{GEM_ROOT}/lib/templates/shared/icons","#{@path}/public/images/")
- end
+
end
@@ -3,6 +3,10 @@
describe InterfaceLift do
it "Should have a version" do
InterfaceLift::VERSION.should_not be_nil
+ end
+
+ it "Should have a DEFAULT_CATALOG_PATH" do
+ InterfaceLift::DEFAULT_CATALOG_PATH.should == "#{ENV["HOME"]}/.interfacelift"
end
it "Should have an Installer class" do

0 comments on commit 1071d5a

Please sign in to comment.