Sha256: 5c74b6996d11f54060da9b4b533625ca686607a164999e29498ca01e1b9c2593

Contents?: true

Size: 1.35 KB

Versions: 15

Compression:

Stored size: 1.35 KB

Contents

class Stylesheet < ActiveRecord::Base
  belongs_to :user
  validates :name, :presence=>true, :length=>{:minimum=>1, :maximum=>80}

  attr_accessor :css
  attr_accessor :fingerprint

  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

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

  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

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

  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

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

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
kit_cms-2.3.22 app/models/stylesheet.rb
kit_cms-2.3.20 app/models/stylesheet.rb
kit_cms-2.3.19 app/models/stylesheet.rb
kit_cms-2.3.18 app/models/stylesheet.rb
kit_cms-2.3.17 app/models/stylesheet.rb
kit_cms-2.3.16 app/models/stylesheet.rb
kit_cms-2.3.15 app/models/stylesheet.rb
kit_cms-2.3.14 app/models/stylesheet.rb
kit_cms-2.3.13 app/models/stylesheet.rb
kit_cms-2.3.11 app/models/stylesheet.rb
kit_cms-2.3.10 app/models/stylesheet.rb
kit_cms-2.3.9 app/models/stylesheet.rb
kit_cms-2.3.8 app/models/stylesheet.rb
kit_cms-2.3.7 app/models/stylesheet.rb
kit_cms-2.3.6 app/models/stylesheet.rb