Class: Plum::ContentSourceRegistry
- Inherits:
-
Object
- Object
- Plum::ContentSourceRegistry
- Defined in:
- lib/plum/content_source_registry.rb
Constant Summary collapse
- RESERVED_HANDLES =
%w[entry entries forms globals nav site].freeze
- HANDLE_PATTERN =
/\A[a-z][a-z0-9_]*\z/
Instance Method Summary collapse
- #clear ⇒ Object
- #handles ⇒ Object
-
#initialize ⇒ ContentSourceRegistry
constructor
A new instance of ContentSourceRegistry.
- #register(handle, source = nil, &block) ⇒ Object
- #to_liquid_context(controller:, site:) ⇒ Object
Constructor Details
#initialize ⇒ ContentSourceRegistry
Returns a new instance of ContentSourceRegistry.
10 11 12 |
# File 'lib/plum/content_source_registry.rb', line 10 def initialize @sources = {} end |
Instance Method Details
#clear ⇒ Object
28 29 30 |
# File 'lib/plum/content_source_registry.rb', line 28 def clear @sources.clear end |
#handles ⇒ Object
24 25 26 |
# File 'lib/plum/content_source_registry.rb', line 24 def handles @sources.keys end |
#register(handle, source = nil, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/plum/content_source_registry.rb', line 14 def register(handle, source = nil, &block) raise ArgumentError, "Provide a source or a block, not both" if source && block raise ArgumentError, "Content source is required" unless source || block normalized_handle = normalize_handle(handle) validate_handle!(normalized_handle) @sources[normalized_handle] = source || block end |
#to_liquid_context(controller:, site:) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/plum/content_source_registry.rb', line 32 def to_liquid_context(controller:, site:) context = ContentSourceContext.new(controller: controller, site: site) @sources.each_with_object({}) do |(handle, source), hash| hash[handle] = resolve_source(handle, source, context) end end |