source: ether_2012/web/cathy/css/blueprint-css/lib/blueprint/custom_layout.rb @ 319

Last change on this file since 319 was 319, checked in by vmipsl, 12 years ago

Import du projet Ether pour le nouveau look 2012

File size: 2.5 KB
Line 
1require 'erb'
2module Blueprint
3  # Generates a custom grid file, using ERB to evaluate custom settings
4  class CustomLayout
5    # path to ERB file used for CSS template
6    CSS_ERB_FILE = File.join(Blueprint::LIB_PATH, 'grid.css.erb')
7
8    attr_writer :column_count, :column_width, :gutter_width, :input_padding,
9                :input_border
10
11    # Column count of generated CSS.  Returns itself or Blueprint's default
12    def column_count
13      (@column_count || Blueprint::COLUMN_COUNT).to_i
14    end
15
16    # Column width (in pixels) of generated CSS.  Returns itself or Blueprint's default
17    def column_width
18      (@column_width || Blueprint::COLUMN_WIDTH).to_i
19    end
20
21    # Gutter width (in pixels) of generated CSS.  Returns itself or Blueprint's default
22    def gutter_width
23      (@gutter_width || Blueprint::GUTTER_WIDTH).to_i
24    end
25
26    def input_padding
27      (@input_padding || Blueprint::INPUT_PADDING).to_i
28    end
29
30    def input_border
31      (@input_border || Blueprint::INPUT_BORDER).to_i
32    end
33
34    # Returns page width (in pixels)
35    def page_width
36      column_count * (column_width + gutter_width) - gutter_width
37    end
38
39    # ==== Options
40    # * <tt>options</tt>
41    #   * <tt>:column_count</tt> -- Sets the column count of generated CSS
42    #   * <tt>:column_width</tt> -- Sets the column width (in pixels) of generated CSS
43    #   * <tt>:gutter_width</tt> -- Sets the gutter width (in pixels) of generated CSS
44    #   * <tt>:input_padding</tt> -- Sets the input padding width (in pixels) of generated CSS
45    #   * <tt>:input_border</tt> -- Sets the border width (in pixels) of generated CSS
46    def initialize(options = {})
47      @column_count   = options[:column_count]
48      @column_width   = options[:column_width]
49      @gutter_width   = options[:gutter_width]
50      @input_padding  = options[:input_padding]
51      @input_border   = options[:input_border]
52    end
53
54    # Boolean value if current settings are Blueprint's defaults
55    def default?
56      self.column_width == Blueprint::COLUMN_WIDTH &&
57      self.column_count == Blueprint::COLUMN_COUNT &&
58      self.gutter_width == Blueprint::GUTTER_WIDTH &&
59      self.input_padding == Blueprint::INPUT_PADDING &&
60      self.input_border == Blueprint::INPUT_BORDER
61    end
62
63    # Loads grid.css.erb file, binds it to current instance, and returns output
64    def generate_grid_css
65      # loads up erb template to evaluate custom widths
66      css = ERB::new(File.path_to_string(CustomLayout::CSS_ERB_FILE))
67
68      # bind it to this instance
69      css.result(binding)
70    end
71  end
72end
Note: See TracBrowser for help on using the repository browser.