Sha256: 46f0d2d1314f9507b64d2648f202aebd3f050bf62f4a48f150018a5a3dd07116
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
require 'cgi' require 'open-uri' require 'active_support' require 'liquid' module JekyllGithubSample class CodeTag < ::Liquid::Tag include TextUtils def initialize(tag_name, params, tokens) github_file_path, @line_start, @line_end = params.split @github_file = FileHelper.new(github_file_path) super end 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_ends = determine_line_numbers(@line_start, @line_end) lines = all_lines[@line_start..@line_end] end lines = remove_common_indentation(lines) lines.join end private def cache @@cache ||= ActiveSupport::Cache::MemoryStore.new end 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 end end Liquid::Template.register_tag('github_sample', JekyllGithubSample::CodeTag)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jekyll_github_sample-0.3.0 | lib/jekyll_github_sample/code_tag.rb |