Skip to content

Commit

Permalink
Use chunky_png instead of rmagick to get rid of imagemagick dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed May 19, 2011
1 parent 32ace0b commit 4775562
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source "http://rubygems.org"

gem "colored"
gem "rmagick"
gem "chunky_png"

group :test do
gem "cucumber", "0.10.2"
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ GEM
celerity (0.8.9)
childprocess (0.1.9)
ffi (~> 1.0.6)
chunky_png (1.2.0)
colored (1.2)
cucumber (0.10.2)
builder (>= 2.1.2)
Expand All @@ -39,7 +40,6 @@ GEM
rack (1.2.2)
rack-test (0.6.0)
rack (>= 1.0)
rmagick (2.13.1)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
Expand All @@ -65,7 +65,7 @@ DEPENDENCIES
aruba (= 0.3.6)
capybara (= 0.4.1.2)
capybara-webkit (= 0.3.0)
chunky_png
colored
cucumber (= 0.10.2)
rmagick
rspec (= 2.6.0)
13 changes: 7 additions & 6 deletions lib/blueprint/compressor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ def generate_css_files
# append semantic class names if set
append_semantic_classes

#attempt to generate a grid.png file
if (grid_builder = GridBuilder.new(:column_width => self.custom_layout.column_width,
:gutter_width => self.custom_layout.gutter_width,
:output_path => File.join(self.destination_path, "src")))
grid_builder.generate!
end
generate_grid_png
end

def append_custom_css(css, current_file_name)
Expand Down Expand Up @@ -242,6 +237,12 @@ def generate_tests
end
end

def generate_grid_png
GridBuilder.new(:column_width => self.custom_layout.column_width,
:gutter_width => self.custom_layout.gutter_width,
:output_path => File.join(self.destination_path, "src")).generate!
end

def output_header
puts "\n"
puts " #{"*" * 100}"
Expand Down
47 changes: 9 additions & 38 deletions lib/blueprint/grid_builder.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
begin
require "rmagick"
require "rvg/rvg"
rescue Exception => e
puts " #{"*" * 100}".red
puts " **".red
puts " ** Warning:".red
puts " ** Could not load the Rmagick gem. Please check your installation.".red
puts " ** grid.png will not be generated.".red
puts " **".red
puts " #{"*" * 100}\n".red
end

module Blueprint
# Uses ImageMagick and RMagick to generate grid.png file
class GridBuilder
begin
include Magick
rescue Exception => e
end

attr_reader :column_width, :gutter_width, :output_path, :able_to_generate

# ==== Options
Expand All @@ -27,36 +8,26 @@ class GridBuilder
# * <tt>:gutter_width</tt> -- Width (in pixels) of current grid gutter
# * <tt>:output_path</tt> -- Output path of grid.png file
def initialize(options={})
@able_to_generate = Magick::Long_version rescue false
return unless @able_to_generate
@column_width = options[:column_width] || Blueprint::COLUMN_WIDTH
@gutter_width = options[:gutter_width] || Blueprint::GUTTER_WIDTH
@output_path = options[:output_path] || Blueprint::SOURCE_PATH
end

# generates (overwriting if necessary) grid.png image to be tiled in background
def generate!
return false unless self.able_to_generate
total_width = self.column_width + self.gutter_width
height = 18
RVG::dpi = 100

width_in_inches = (total_width.to_f/RVG::dpi).in
height_in_inches = (height.to_f/RVG::dpi).in
rvg = RVG.new(width_in_inches, height_in_inches).viewbox(0, 0, total_width, height) do |canvas|
canvas.background_fill = "white"
height = 18

canvas.g do |column|
column.rect(self.column_width - 1, height).styles(:fill => "#e8effb")
end
white = ChunkyPNG::Color.from_hex("ffffff")
background = ChunkyPNG::Color.from_hex("e8effb")
line = ChunkyPNG::Color.from_hex("e9e9e9")

canvas.g do |baseline|
baseline.line(0, (height - 1), total_width, (height - 1)).styles(:fill => "#e9e9e9")
end
end
png = ChunkyPNG::Image.new(total_width, height, white)
png.rect(0, 0, column_width - 1, height, background, background)
png.rect(0, height - 1, total_width, height - 1, line, line)

FileUtils.mkdir self.output_path unless File.exists? self.output_path
rvg.draw.write(File.join(self.output_path, "grid.png"))
FileUtils.mkdir(self.output_path) unless File.exists?(self.output_path)
png.save(File.join(self.output_path, "grid.png"))
end
end
end

0 comments on commit 4775562

Please sign in to comment.