Permalink
Browse files

rails pluginization & rake task - getting started

  • Loading branch information...
1 parent 870aabc commit 5e3b7a2036ce322c89a7d075a79e8f6ff05a001c @tjennings tjennings committed Nov 15, 2009
View
@@ -12,6 +12,10 @@ opts = OptionParser.new do |opts|
options[:css_file] = file
end
+ opts.on("-p", "--path-prefix PREFIX", "prepend sprite paths with the given string") do |prefix|
+ options[:path_prefix] = prefix
+ end
+
opts.on_tail("-h", "--help", "Prints this message") do
puts opts
exit
@@ -1,61 +1,61 @@
+ .apple_iphone {
+ background: transparent url(/tacos/apple/sprite.png) -234px 0px no-repeat;
+ width:116;
+ height:38;
+ text-indent:-5000px;
+ }
+
.apple_itunes {
- background: transparent url(/apple/sprite.png) -350px 0px no-repeat;
+ background: transparent url(/tacos/apple/sprite.png) -350px 0px no-repeat;
width:116;
height:38;
text-indent:-5000px;
}
.apple_mac {
- background: transparent url(/apple/sprite.png) -466px 0px no-repeat;
+ background: transparent url(/tacos/apple/sprite.png) -466px 0px no-repeat;
width:116;
height:38;
text-indent:-5000px;
}
.apple_apple {
- background: transparent url(/apple/sprite.png) 0px 0px no-repeat;
+ background: transparent url(/tacos/apple/sprite.png) 0px 0px no-repeat;
width:117;
height:38;
text-indent:-5000px;
}
- .apple_store {
- background: transparent url(/apple/sprite.png) -744px 0px no-repeat;
+ .apple_support {
+ background: transparent url(/tacos/apple/sprite.png) -860px 0px no-repeat;
width:116;
height:38;
text-indent:-5000px;
}
.apple_search {
- background: transparent url(/apple/sprite.png) -582px 0px no-repeat;
+ background: transparent url(/tacos/apple/sprite.png) -582px 0px no-repeat;
width:162;
height:38;
text-indent:-5000px;
}
.apple_divider {
- background: transparent url(/apple/sprite.png) -117px 0px no-repeat;
+ background: transparent url(/tacos/apple/sprite.png) -117px 0px no-repeat;
width:1;
height:38;
text-indent:-5000px;
}
- .apple_support {
- background: transparent url(/apple/sprite.png) -860px 0px no-repeat;
+ .apple_store {
+ background: transparent url(/tacos/apple/sprite.png) -744px 0px no-repeat;
width:116;
height:38;
text-indent:-5000px;
}
.apple_downloads {
- background: transparent url(/apple/sprite.png) -118px 0px no-repeat;
- width:116;
- height:38;
- text-indent:-5000px;
- }
-
- .apple_iphone {
- background: transparent url(/apple/sprite.png) -234px 0px no-repeat;
+ background: transparent url(/tacos/apple/sprite.png) -118px 0px no-repeat;
width:116;
height:38;
text-indent:-5000px;
View
@@ -0,0 +1 @@
+# Include hook code here
@@ -1,5 +1,6 @@
class DirectoryProcessor
- def initialize(dir)
+ def initialize(dir, options = {})
+ @options = options
@dir = dir
files = images
@sprite = PNG::Sprite.new
@@ -36,7 +37,9 @@ def dir_name
def image_loc
#TODO: Lame!
- ("/" + @dir + "/sprite.png").gsub("/./", "/")
+ base = ("/" + @dir + "/sprite.png").gsub("/./", "/").gsub("//", "/")
+ base = @options[:path_prefix] + base if @options[:path_prefix]
+ base
end
FRAG = <<-EOF
@@ -17,7 +17,7 @@ def directories
end
def dir_processors
- directories.map{|d| DirectoryProcessor.new(d)}
+ directories.map{|d| DirectoryProcessor.new(d, @options)}
end
def cleanup
@@ -22,9 +22,6 @@
read("#{@expected_dir}/merge_right_test.png").should == read("#{@tmp_dir}/merge_right_test.png")
end
- def read(file_name)
- File.read(file_name)
- end
end
describe "Dir sprite" do
@@ -107,7 +104,7 @@ def read(file_name)
before :all do
@dir = File.dirname(__FILE__) + "/sprite_dirs"
@css_file = @dir + "/sprite.css"
- @spittle = Spittle::Processor.new(:source => @dir, :css_file => @css_file)
+ @spittle = Spittle::Processor.new(:path_prefix => "/images", :source => @dir, :css_file => @css_file)
@spittle.write
end
@@ -118,6 +115,11 @@ def read(file_name)
File.exists?(@dir + "/words/sprite.png").should be_false
end
+ it "prepends a path prefix to all sprites in the css file" do
+ file = read(@css_file)
+ file.should include("/images/spec/sprite_dirs/words")
+ end
+
it "can find all the sprite directories" do
dirs = @spittle.directories.map{|d| d.split('/').last}
dirs.should include( "words" )
@@ -132,3 +134,8 @@ def read(file_name)
File.exists?(@dir + "/words/fragment.css").should be_true
end
end
+
+def read(file_name)
+ File.read(file_name)
+end
+
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :spittle do
+# # Task goes here
+# end

0 comments on commit 5e3b7a2

Please sign in to comment.