Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use chunky_png instead of rmagick to get rid of imagemagick dependencies

  • Loading branch information...
commit 477556257a33d3059a0cd45e65ff1317d4c4a091 1 parent 32ace0b
@joshuaclayton authored
View
2  Gemfile
@@ -1,7 +1,7 @@
source "http://rubygems.org"
gem "colored"
-gem "rmagick"
+gem "chunky_png"
group :test do
gem "cucumber", "0.10.2"
View
4 Gemfile.lock
@@ -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)
@@ -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)
@@ -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)
View
13 lib/blueprint/compressor.rb
@@ -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)
@@ -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}"
View
47 lib/blueprint/grid_builder.rb
@@ -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
@@ -27,8 +8,6 @@ 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
@@ -36,27 +15,19 @@ def initialize(options={})
# 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
Please sign in to comment.
Something went wrong with that request. Please try again.