11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/loyal_core/acts/skin_dish_able.rb', line 11
def loyal_core_acts_as_skin_dish_able *args
options = args.
has_one :skin_dish, :class_name => '::LoyalCore::Skin::Dish', :as => :target
has_one :skin_recipe, :class_name => '::LoyalCore::Skin::Recipe',
:through => :skin_dish, :source => :recipe
attr_accessible :skin_recipe_id
define_method :skin_recipe_id do
@skin_recipe_id ||= self.skin_recipe.try(:id)
end
define_method :skin_recipe_id= do |recipe_id|
@skin_recipe_id ||= recipe_id
end
before_validation do |r|
r.skin_recipe = ::LoyalCore::Skin::Recipe.find_by_id(r.skin_recipe_id)
end
define_method :skin_recipe_html do |context|
html = ''
if self.skin_recipe
if self.skin_recipe.assets_path.present?
html << context.stylesheet_link_tag(self.skin_recipe.assets_path)
end
if self.skin_recipe.stylesheet_text.present?
html += <<-HTML
<style type='text/css'>
#{self.skin_recipe.stylesheet_text}
</style>
HTML
end
end
html
end
end
|