Class: Blueprint::GridBuilder
- Inherits:
-
Object
- Object
- Blueprint::GridBuilder
- Defined in:
- lib/blueprint-css/lib/blueprint/grid_builder.rb
Overview
Uses ImageMagick and RMagick to generate grid.png file
Instance Attribute Summary collapse
-
#able_to_generate ⇒ Object
readonly
Returns the value of attribute able_to_generate.
-
#column_width ⇒ Object
readonly
Returns the value of attribute column_width.
-
#gutter_width ⇒ Object
readonly
Returns the value of attribute gutter_width.
-
#output_path ⇒ Object
readonly
Returns the value of attribute output_path.
Instance Method Summary collapse
-
#generate! ⇒ Object
generates (overwriting if necessary) grid.png image to be tiled in background.
-
#initialize(options = {}) ⇒ GridBuilder
constructor
Options *
options
*:column_width
– Width (in pixels) of current grid column *:gutter_width
– Width (in pixels) of current grid gutter *:output_path
– Output path of grid.png file.
Constructor Details
#initialize(options = {}) ⇒ GridBuilder
Options
-
options
-
:column_width
– Width (in pixels) of current grid column -
:gutter_width
– Width (in pixels) of current grid gutter -
:output_path
– Output path of grid.png file
-
23 24 25 26 27 28 29 |
# File 'lib/blueprint-css/lib/blueprint/grid_builder.rb', line 23 def initialize(={}) @able_to_generate = Magick::Long_version rescue false return unless @able_to_generate @column_width = [:column_width] || Blueprint::COLUMN_WIDTH @gutter_width = [:gutter_width] || Blueprint::GUTTER_WIDTH @output_path = [:output_path] || Blueprint::SOURCE_PATH end |
Instance Attribute Details
#able_to_generate ⇒ Object (readonly)
Returns the value of attribute able_to_generate.
16 17 18 |
# File 'lib/blueprint-css/lib/blueprint/grid_builder.rb', line 16 def able_to_generate @able_to_generate end |
#column_width ⇒ Object (readonly)
Returns the value of attribute column_width.
16 17 18 |
# File 'lib/blueprint-css/lib/blueprint/grid_builder.rb', line 16 def column_width @column_width end |
#gutter_width ⇒ Object (readonly)
Returns the value of attribute gutter_width.
16 17 18 |
# File 'lib/blueprint-css/lib/blueprint/grid_builder.rb', line 16 def gutter_width @gutter_width end |
#output_path ⇒ Object (readonly)
Returns the value of attribute output_path.
16 17 18 |
# File 'lib/blueprint-css/lib/blueprint/grid_builder.rb', line 16 def output_path @output_path end |
Instance Method Details
#generate! ⇒ Object
generates (overwriting if necessary) grid.png image to be tiled in background
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/blueprint-css/lib/blueprint/grid_builder.rb', line 32 def generate! return false unless self.able_to_generate total_width = self.column_width + self.gutter_width height = 18 RVG::dpi = 100 rvg = RVG.new((total_width.to_f/RVG::dpi).in, (height.to_f/RVG::dpi).in).viewbox(0, 0, total_width, height) do |canvas| canvas.background_fill = 'white' canvas.g do |column| column.rect(self.column_width - 1, height).styles(:fill => "#e8effb") end canvas.g do |baseline| baseline.line(0, (height - 1), total_width, (height- 1)).styles(:fill => "#e9e9e9") end end FileUtils.mkdir self.output_path unless File.exists? self.output_path rvg.draw.write(File.join(self.output_path, "grid.png")) end |