Class: Pebblebed::Parts
- Inherits:
-
Object
- Object
- Pebblebed::Parts
- Defined in:
- lib/pebblebed/parts.rb
Overview
A class to help consumers of layout parts embed parts
Instance Attribute Summary collapse
-
#composition_strategy ⇒ Object
Returns the value of attribute composition_strategy.
Class Method Summary collapse
-
.register_composition_strategy(name, &block) ⇒ Object
Register a new composition strategy handler.
Instance Method Summary collapse
-
#initialize(connector) ⇒ Parts
constructor
A new instance of Parts.
- #javascript_urls ⇒ Object
-
#manifests ⇒ Object
All part manifests for all configured pebbles as a hash of DeepStructs.
-
#markup(partspec, params = nil) ⇒ Object
Generates the markup for the part according to the composition strategy.
- #reload_manifest ⇒ Object
- #stylesheet_urls ⇒ Object
Constructor Details
#initialize(connector) ⇒ Parts
Returns a new instance of Parts.
14 15 16 17 18 |
# File 'lib/pebblebed/parts.rb', line 14 def initialize(connector) @composition_strategy = :ssi # <- It's the best! Use Nginx with SSI @preloadable = {} # <- A cache to remember which parts are preloadable @connector = connector end |
Instance Attribute Details
#composition_strategy ⇒ Object
Returns the value of attribute composition_strategy.
5 6 7 |
# File 'lib/pebblebed/parts.rb', line 5 def composition_strategy @composition_strategy end |
Class Method Details
.register_composition_strategy(name, &block) ⇒ Object
Register a new composition strategy handler. The block must accept two parameters: |url, params| and is expected to return whatever markup is needed to make it happen.
58 59 60 |
# File 'lib/pebblebed/parts.rb', line 58 def self.register_composition_strategy(name, &block) @composition_strategies[name.to_sym] = block end |
Instance Method Details
#javascript_urls ⇒ Object
50 51 52 53 54 |
# File 'lib/pebblebed/parts.rb', line 50 def javascript_urls manifests.keys.map do |service| @connector[service].service_url("/parts/assets/parts.js") end end |
#manifests ⇒ Object
All part manifests for all configured pebbles as a hash of DeepStructs
21 22 23 24 25 |
# File 'lib/pebblebed/parts.rb', line 21 def manifests @manifests ||= @connector.quorum.get("/parts") @manifests.each { |k,v| @manifests.delete(k) if v.is_a?(Pebblebed::HttpError) } @manifests end |
#markup(partspec, params = nil) ⇒ Object
Generates the markup for the part according to the composition strategy
38 39 40 41 42 |
# File 'lib/pebblebed/parts.rb', line 38 def markup(partspec, params = nil) ["<div data-pebbles-component=\"#{partspec}\" #{self.class.data_attributes(params || {})}>", composition_markup_from_partspec(partspec, params), "</div>"].join end |
#reload_manifest ⇒ Object
27 28 29 |
# File 'lib/pebblebed/parts.rb', line 27 def reload_manifest @manifests = nil end |
#stylesheet_urls ⇒ Object
44 45 46 47 48 |
# File 'lib/pebblebed/parts.rb', line 44 def stylesheet_urls manifests.keys.map do |service| @connector[service].service_url("/parts/assets/parts.css") end end |