Class: JekyllGithubSample::CodeTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- JekyllGithubSample::CodeTag
- Includes:
- TextUtils
- Defined in:
- lib/jekyll_github_sample/code_tag.rb
Direct Known Subclasses
Constant Summary
Constants included from TextUtils
Instance Method Summary collapse
-
#initialize(tag_name, params, tokens) ⇒ CodeTag
constructor
A new instance of CodeTag.
- #render(context) ⇒ Object
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 |