Class: Deplate::Cache
- Inherits:
-
Object
- Object
- Deplate::Cache
- Defined in:
- lib/deplate/cache.rb
Overview
Description
This class provides a cache for dynamically generated classes.
Constant Summary collapse
- @@custom_particles =
{}
- @@custom_macros =
{}
- @@custom_elements =
{}
- @@custom_regions =
{}
- @@custom_commands =
{}
Instance Attribute Summary collapse
-
#cls ⇒ Object
readonly
Returns the value of attribute cls.
Class Method Summary collapse
- .command(deplate, body, args) ⇒ Object
- .element(deplate, body, args) ⇒ Object
- .macro(deplate, body, args) ⇒ Object
- .particle(deplate, body, args) ⇒ Object
- .region(deplate, body, args) ⇒ Object
Instance Method Summary collapse
- #get_formatter_name(specific) ⇒ Object
-
#initialize(cache, super_class, deplate, body, args = {}) ⇒ Cache
constructor
A new instance of Cache.
- #retrieve_particle(body, specific = false) ⇒ Object
- #store_particle(body, specific = false) ⇒ Object
Constructor Details
#initialize(cache, super_class, deplate, body, args = {}) ⇒ Cache
Returns a new instance of Cache.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/deplate/cache.rb', line 74 def initialize(cache, super_class, deplate, body, args={}) @deplate = deplate @cache = cache specific = args[:specific] retrieve_particle(body, specific) unless @cls @cls = Class.new(super_class) if body.kind_of?(Proc) @cls.class_eval(&body) else @cls.class_eval(body) end store_particle(body, specific) end if @cls and block_given? yield(@cls) end end |
Instance Attribute Details
#cls ⇒ Object (readonly)
Returns the value of attribute cls.
18 19 20 |
# File 'lib/deplate/cache.rb', line 18 def cls @cls end |
Class Method Details
.command(deplate, body, args) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/deplate/cache.rb', line 43 def command(deplate, body, args) register = args[:register] parent = args[:super] || Deplate::Command new(@@custom_commands, parent, deplate, body, args) do |cls| if register deplate.input.register_command(cls, args) end end end |
.element(deplate, body, args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/deplate/cache.rb', line 32 def element(deplate, body, args) register = args[:register] parent = args[:super] || Deplate::Element new(@@custom_elements, parent, deplate, body, args) do |cls| if register args[:id] = body deplate.input.register_element(cls, args) end end end |
.macro(deplate, body, args) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/deplate/cache.rb', line 63 def macro(deplate, body, args) register = args[:register] parent = args[:super] || Deplate::Region new(@@custom_macros, parent, deplate, body, args) do |cls| if register deplate.input.register_macro(cls, args) end end end |
.particle(deplate, body, args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/deplate/cache.rb', line 21 def particle(deplate, body, args) register = args[:register] parent = args[:super] || Deplate::Particle new(@@custom_particles, parent, deplate, body, args) do |cls| if register args[:id] = body deplate.input.register_particle(cls, args) end end end |
.region(deplate, body, args) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/deplate/cache.rb', line 53 def region(deplate, body, args) register = args[:register] parent = args[:super] || Deplate::Region new(@@custom_regions, parent, deplate, body, args) do |cls| if register deplate.input.register_region(cls, args) end end end |
Instance Method Details
#get_formatter_name(specific) ⇒ Object
105 106 107 |
# File 'lib/deplate/cache.rb', line 105 def get_formatter_name(specific) return specific ? @deplate.formatter.formatter_name : :general end |
#retrieve_particle(body, specific = false) ⇒ Object
93 94 95 96 97 |
# File 'lib/deplate/cache.rb', line 93 def retrieve_particle(body, specific=false) fmt = get_formatter_name(specific) particles = @cache[fmt] ||= {} @cls = particles[body] end |
#store_particle(body, specific = false) ⇒ Object
99 100 101 102 103 |
# File 'lib/deplate/cache.rb', line 99 def store_particle(body, specific=false) fmt = get_formatter_name(specific) particles = @cache[fmt] ||= {} particles[body] = @cls end |