Class: Stylesheet

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/stylesheet.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cssObject

Returns the value of attribute css.



5
6
7
# File 'app/models/stylesheet.rb', line 5

def css
  @css
end

#fingerprintObject

Returns the value of attribute fingerprint.



6
7
8
# File 'app/models/stylesheet.rb', line 6

def fingerprint
  @fingerprint
end

Class Method Details

.cache_key(system_id, name) ⇒ Object



27
28
29
# File 'app/models/stylesheet.rb', line 27

def self.cache_key(system_id, name)
  "kit_stylesheet_#{name.downcase}-#{system_id}"
end

.create_default(sid, user_id) ⇒ Object



62
63
64
# File 'app/models/stylesheet.rb', line 62

def self.create_default(sid, user_id)
  Stylesheet.create(:system_id=>sid, :user_id=>user_id, :name=>"application", :body=>Stylesheet.default_body)
end

.default_bodyObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/stylesheet.rb', line 31

def self.default_body 
%Q[
/* Sassy CSS Stylesheet Examples - can use normal CSS3, but also: */

$var: #123;
$big: 12px;

.example {
color: $var;
span: {
  font-size: $big;
}
}

.more-example {
@extend .example;
background-color: #000;
}

@mixin left_with_margin($m) {
float: left;
margin: $m;
}

#data {
@include left_with_margin(10px);
}
]

end

.fetch(system_id, name) ⇒ Object



8
9
10
11
12
13
14
# File 'app/models/stylesheet.rb', line 8

def self.fetch(system_id, name)
  Rails.cache.fetch(Stylesheet.cache_key(system_id, name.downcase)) do 
    sheet = Stylesheet.sys(system_id).where(:name=>name.downcase).first
    sheet.generate_css if sheet
    sheet
  end
end

Instance Method Details

#generate_cssObject



20
21
22
23
24
25
# File 'app/models/stylesheet.rb', line 20

def generate_css
    self.css = Sass::Engine.new(self.body, :syntax=>:scss, :style=>Rails.env=='development' ? :expanded : :compressed).to_css
    self.fingerprint = Digest::MD5.hexdigest("#{Time.now}-#{self.id}")

    return self
end

#kit_nameObject



16
17
18
# File 'app/models/stylesheet.rb', line 16

def kit_name
  "#{self.name.downcase}-#{self.fingerprint}.css".downcase
end