class JekyllGithubSample::CodeTag

Public Class Methods

new(tag_name, params, tokens) click to toggle source
Calls superclass method
# 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

Public Instance Methods

render(context) click to toggle source
# 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

Private Instance Methods

cache() click to toggle source
# File lib/jekyll_github_sample/code_tag.rb, line 33
def cache
  @@cache ||= ActiveSupport::Cache::MemoryStore.new
end
determine_line_numbers(first, last) click to toggle source
# File lib/jekyll_github_sample/code_tag.rb, line 37
def determine_line_numbers(first, last)
  if first.nil? && last.nil?
    first = 0
    last  = -1
  elsif last.nil?
    last = first
  end

  [first.to_i, last.to_i]
end