Class: Liquid::CustomBlocks::WithGlossaristContext
- Inherits:
-
Block
- Object
- Block
- Liquid::CustomBlocks::WithGlossaristContext
- Defined in:
- lib/liquid/custom_blocks/with_glossarist_context.rb
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ WithGlossaristContext
constructor
A new instance of WithGlossaristContext.
- #load_collection(folder_path) ⇒ Object
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ WithGlossaristContext
Returns a new instance of WithGlossaristContext.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/liquid/custom_blocks/with_glossarist_context.rb', line 4 def initialize(tag_name, markup, tokens) super @contexts = [] @filters = {} contexts, filters = markup.split(";", 2) if filters && !filters.empty? filters.strip.gsub(/^['"]|['"]$/, "").split(";").each do |filter| property, value = filter.split("=") @filters[property] = value end end contexts.split(",").each do |context| context_name, file_path = context.split("=").map(&:strip) @contexts << { name: context_name, file_path: file_path, } end end |
Instance Method Details
#load_collection(folder_path) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/liquid/custom_blocks/with_glossarist_context.rb', line 30 def load_collection(folder_path) @@collections ||= {} return @@collections[folder_path] if @@collections[folder_path] collection = ::Glossarist::ManagedConceptCollection.new collection.load_from_files(folder_path) @@collections[folder_path] = collection end |
#render(context) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/liquid/custom_blocks/with_glossarist_context.rb', line 40 def render(context) @contexts.each do |local_context| context_file = local_context[:file_path].strip collection = load_collection(context_file) context[local_context[:name]] = Liquid::Drops::ConceptsDrop.new(collection, @filters) end super end |