Class: Blueprint::CustomLayout

Inherits:
Object
  • Object
show all
Defined in:
lib/blueprint-css/lib/blueprint/custom_layout.rb

Overview

Generates a custom grid file, using ERB to evaluate custom settings

Constant Summary collapse

CSS_ERB_FILE =

path to ERB file used for CSS template

File.join(Blueprint::LIB_PATH, 'grid.css.erb')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CustomLayout

Options

  • options

    • :column_count – Sets the column count of generated CSS

    • :column_width – Sets the column width (in pixels) of generated CSS

    • :gutter_width – Sets the gutter width (in pixels) of generated CSS

    • :input_padding – Sets the input padding width (in pixels) of generated CSS

    • :input_border – Sets the border width (in pixels) of generated CSS



45
46
47
48
49
50
51
# File 'lib/blueprint-css/lib/blueprint/custom_layout.rb', line 45

def initialize(options = {})
  @column_count   = options[:column_count]
  @column_width   = options[:column_width]
  @gutter_width   = options[:gutter_width]
  @input_padding  = options[:input_padding]
  @input_border   = options[:input_border]
end

Instance Attribute Details

#column_countObject

Column count of generated CSS. Returns itself or Blueprint’s default



11
12
13
# File 'lib/blueprint-css/lib/blueprint/custom_layout.rb', line 11

def column_count
  (@column_count || Blueprint::COLUMN_COUNT).to_i
end

#column_widthObject

Column width (in pixels) of generated CSS. Returns itself or Blueprint’s default



16
17
18
# File 'lib/blueprint-css/lib/blueprint/custom_layout.rb', line 16

def column_width
  (@column_width || Blueprint::COLUMN_WIDTH).to_i
end

#gutter_widthObject

Gutter width (in pixels) of generated CSS. Returns itself or Blueprint’s default



21
22
23
# File 'lib/blueprint-css/lib/blueprint/custom_layout.rb', line 21

def gutter_width
  (@gutter_width || Blueprint::GUTTER_WIDTH).to_i
end

#input_borderObject



29
30
31
# File 'lib/blueprint-css/lib/blueprint/custom_layout.rb', line 29

def input_border
  (@input_border || Blueprint::INPUT_BORDER).to_i
end

#input_paddingObject



25
26
27
# File 'lib/blueprint-css/lib/blueprint/custom_layout.rb', line 25

def input_padding
  (@input_padding || Blueprint::INPUT_PADDING).to_i
end

Instance Method Details

#default?Boolean

Boolean value if current settings are Blueprint’s defaults

Returns:

  • (Boolean)


54
55
56
57
58
59
60
# File 'lib/blueprint-css/lib/blueprint/custom_layout.rb', line 54

def default?
  self.column_width == Blueprint::COLUMN_WIDTH && 
  self.column_count == Blueprint::COLUMN_COUNT && 
  self.gutter_width == Blueprint::GUTTER_WIDTH && 
  self.input_padding == Blueprint::INPUT_PADDING && 
  self.input_border == Blueprint::INPUT_BORDER
end

#generate_grid_cssObject

Loads grid.css.erb file, binds it to current instance, and returns output



63
64
65
66
67
68
69
# File 'lib/blueprint-css/lib/blueprint/custom_layout.rb', line 63

def generate_grid_css
  # loads up erb template to evaluate custom widths
  css = ERB::new(File.path_to_string(CustomLayout::CSS_ERB_FILE))

  # bind it to this instance
  css.result(binding)
end

#page_widthObject

Returns page width (in pixels)



34
35
36
# File 'lib/blueprint-css/lib/blueprint/custom_layout.rb', line 34

def page_width
  column_count * (column_width + gutter_width) - gutter_width
end