Class: Liquid::CustomBlocks::WithGlossaristContext

Inherits:
Block
  • Object
show all
Defined in:
lib/liquid/custom_blocks/with_glossarist_context.rb

Instance Method Summary collapse

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

#render(context) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/liquid/custom_blocks/with_glossarist_context.rb', line 30

def render(context)
  @contexts.each do |local_context|
    context_file = local_context[:file_path].strip
    collection = ::Glossarist::ManagedConceptCollection.new
    collection.load_from_files(context_file)

    context[local_context[:name]] = Liquid::Drops::ConceptsDrop.new(collection, @filters)
  end

  super
end