Class: Compass::GridBuilder
- Inherits:
-
Object
- Object
- Compass::GridBuilder
- Includes:
- Actions
- Defined in:
- lib/compass/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.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#gutter_width ⇒ Object
readonly
Returns the value of attribute gutter_width.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Attributes included from Actions
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 *:height– Height (in pixels) of a row *:filename– Output path of grid.png file. - #working_path ⇒ Object
Methods included from Actions
#basename, #compile, #copy, #directory, #process_erb, #relativize, #remove, #separate, #strip_trailing_separator, #write_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 -
:height– Height (in pixels) of a row -
:filename– Output path of grid.png file
-
27 28 29 30 31 32 33 34 35 |
# File 'lib/compass/grid_builder.rb', line 27 def initialize(={}) @able_to_generate = Magick::Long_version rescue false return unless @able_to_generate @column_width = [:column_width] @gutter_width = [:gutter_width] @height = [:height] || 20 @filename = [:filename] = end |
Instance Attribute Details
#able_to_generate ⇒ Object (readonly)
Returns the value of attribute able_to_generate.
19 20 21 |
# File 'lib/compass/grid_builder.rb', line 19 def able_to_generate @able_to_generate end |
#column_width ⇒ Object (readonly)
Returns the value of attribute column_width.
19 20 21 |
# File 'lib/compass/grid_builder.rb', line 19 def column_width @column_width end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
19 20 21 |
# File 'lib/compass/grid_builder.rb', line 19 def filename @filename end |
#gutter_width ⇒ Object (readonly)
Returns the value of attribute gutter_width.
19 20 21 |
# File 'lib/compass/grid_builder.rb', line 19 def gutter_width @gutter_width end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/compass/grid_builder.rb', line 19 def end |
Instance Method Details
#generate! ⇒ Object
generates (overwriting if necessary) grid.png image to be tiled in background
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/compass/grid_builder.rb', line 42 def generate! return false unless self.able_to_generate total_width = self.column_width + self.gutter_width 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 if File.exists?(filename) if [:force] overwrite = true else msg = "#{filename} already exists. Overwrite with --force." raise Compass::FilesystemConflict.new(msg) end end directory File.dirname(filename) logger.record((overwrite ? :overwrite : :create), basename(filename)) unless [:dry_run] rvg.draw.write(filename) else true end end |
#working_path ⇒ Object
37 38 39 |
# File 'lib/compass/grid_builder.rb', line 37 def working_path [:working_path] end |