Class: JekyllGithubSample::CodeTag

Inherits:
Liquid::Tag
  • Object
show all
Includes:
TextUtils
Defined in:
lib/jekyll_github_sample/code_tag.rb

Direct Known Subclasses

ReferenceTag

Constant Summary

Constants included from TextUtils

TextUtils::INDEN_REGEX

Instance Method Summary collapse

Methods included from TextUtils

#extract_tagged_lines, #remove_common_indentation

Constructor Details

#initialize(tag_name, params, tokens) ⇒ CodeTag

Returns a new instance of CodeTag.



11
12
13
14
15
# File 'lib/jekyll_github_sample/code_tag.rb', line 11

def initialize(tag_name, params, tokens)
  github_file_path, @line_start, @line_end = params.split
  @github_file                             = FileHelper.new(github_file_path)
  super
end

Instance Method Details

#render(context) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jekyll_github_sample/code_tag.rb', line 17

def render(context)
  all_lines = cache.fetch(@github_file.raw_uri) do
    open(@github_file.raw_uri).readlines
  end
  if @line_start.respond_to?(:match) and tag_match = @line_start.match(/^tag:(.*)/)
    lines     = extract_tagged_lines(all_lines, tag_match[1])
  else
    @line_start, @line_end = determine_line_numbers(@line_start, @line_end)
    lines     = all_lines[@line_start..@line_end]
  end
  lines     = remove_common_indentation(lines)
  lines.join
end