Class: Blueprint::GridBuilder
- Inherits:
-
Object
- Object
- Blueprint::GridBuilder
- Defined in:
- lib/template/css/blueprint/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
-
30 31 32 33 34 35 36 |
# File 'lib/template/css/blueprint/lib/blueprint/grid_builder.rb', line 30 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.
23 24 25 |
# File 'lib/template/css/blueprint/lib/blueprint/grid_builder.rb', line 23 def able_to_generate @able_to_generate end |
#column_width ⇒ Object (readonly)
Returns the value of attribute column_width.
23 24 25 |
# File 'lib/template/css/blueprint/lib/blueprint/grid_builder.rb', line 23 def column_width @column_width end |
#gutter_width ⇒ Object (readonly)
Returns the value of attribute gutter_width.
23 24 25 |
# File 'lib/template/css/blueprint/lib/blueprint/grid_builder.rb', line 23 def gutter_width @gutter_width end |
#output_path ⇒ Object (readonly)
Returns the value of attribute output_path.
23 24 25 |
# File 'lib/template/css/blueprint/lib/blueprint/grid_builder.rb', line 23 def output_path @output_path end |
Instance Method Details
#generate! ⇒ Object
generates (overwriting if necessary) grid.png image to be tiled in background
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/template/css/blueprint/lib/blueprint/grid_builder.rb', line 39 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" 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 |