Class: Jekyll::Faker::Tag

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/jekyll/faker/tag.rb

Instance Method Summary collapse

Instance Method Details

#handle_missing_faker_method(e, args:) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/jekyll/faker/tag.rb', line 50

def handle_missing_faker_method(e, args:)
  if e.message =~ %r!Faker!i
    raise ArgumentError, "Unknown faker #{
      args[:argv1]
    }"
  else
    raise e
  end
end

#render(ctx) ⇒ String

Note:

Defaults are ran twice just incase the content type changes, at that point there might be something that has to change in the new content.

– rubocop:disable Layout/SpaceInsideStringInterpolation Render the tag, run the proxies, set the defaults. –



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jekyll/faker/tag.rb', line 22

def render(ctx)
  args = Liquid::Tag::Parser.new(@markup)
  fakr = discover(camelize(args[:argv1]))

  out = ""
  args.each do |k, v|
    next if k == :argv1

    begin
      result = fakr.send(k, *Array(v))
      Array(result).each do |sv|
        ctx["faker"] = {
          "val" => sv,
        }

        out += super
      end
    rescue NoMethodError => e
      handle_missing_faker_method(e, {
        args: args,
      })
    end
  end

  out
end