Class: Blueprint::CustomLayout

Inherits:
Object
  • Object
show all
Defined in:
lib/template/css/blueprint/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



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

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



12
13
14
# File 'lib/template/css/blueprint/lib/blueprint/custom_layout.rb', line 12

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



17
18
19
# File 'lib/template/css/blueprint/lib/blueprint/custom_layout.rb', line 17

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



22
23
24
# File 'lib/template/css/blueprint/lib/blueprint/custom_layout.rb', line 22

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

#input_borderObject



30
31
32
# File 'lib/template/css/blueprint/lib/blueprint/custom_layout.rb', line 30

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

#input_paddingObject



26
27
28
# File 'lib/template/css/blueprint/lib/blueprint/custom_layout.rb', line 26

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)


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

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



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

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)



35
36
37
# File 'lib/template/css/blueprint/lib/blueprint/custom_layout.rb', line 35

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