Class: AttachmentMagick::Configuration

Inherits:
Object
  • Object
show all
Includes:
CssParser
Defined in:
lib/attachment_magick/configuration/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



14
15
16
17
18
19
20
21
# File 'lib/attachment_magick/configuration/configuration.rb', line 14

def initialize
  @columns_amount         = 19
  @columns_width          = 54
  @gutter                 = 3
  @custom_styles          = []
  @orms                   = ["Mongoid"]
  @default_add_partial    = "/attachment_magick/add_image"
end

Instance Attribute Details

#columns_amountObject

Returns the value of attribute columns_amount.



8
9
10
# File 'lib/attachment_magick/configuration/configuration.rb', line 8

def columns_amount
  @columns_amount
end

#columns_widthObject

Returns the value of attribute columns_width.



9
10
11
# File 'lib/attachment_magick/configuration/configuration.rb', line 9

def columns_width
  @columns_width
end

#default_add_partialObject

Returns the value of attribute default_add_partial.



11
12
13
# File 'lib/attachment_magick/configuration/configuration.rb', line 11

def default_add_partial
  @default_add_partial
end

#gutterObject

Returns the value of attribute gutter.



10
11
12
# File 'lib/attachment_magick/configuration/configuration.rb', line 10

def gutter
  @gutter
end

#ormsObject

Returns the value of attribute orms.



12
13
14
# File 'lib/attachment_magick/configuration/configuration.rb', line 12

def orms
  @orms
end

Instance Method Details

#custom_styles(&block) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/attachment_magick/configuration/configuration.rb', line 23

def custom_styles(&block)
  if block_given?
    @custom_styles = CustomStyle.new
    @custom_styles.instance_eval(&block)
  else
    return @custom_styles
  end
end

#parse_stylesheet(stylesheet) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/attachment_magick/configuration/configuration.rb', line 32

def parse_stylesheet(stylesheet)
  return if stylesheet.blank?

  stylesheet_file = Dir.glob(File.join(Rails.root, "public", "**", "#{stylesheet}")).first
  parser          = CssParser::Parser.new

  if stylesheet_file
    parser.load_uri!(stylesheet_file)

    all_containers  = parser.find_by_selector(/\.container/).keys
    container       = all_containers.first
    container_width = parser.find_by_selector(/\.container/)[container]["width"].to_i
    grid_1          = parser.find_by_selector(/\b(grid_1)\b/).values
    grid_1_width    = grid_1.detect{|attr| attr["width"]}["width"].to_i
    gutter          = grid_1.map{|attr| attr.values_at('margin-left')}.flatten.compact.join.to_i

    @columns_width  = grid_1_width
    @gutter         = gutter
    @columns_amount = container_width/(@columns_width+@gutter*2)
  end
end