jekyll-github-comments 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/jekyll-github-comments.rb +185 -0
- metadata +72 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 931c91d19357feba1e0fae3750f040cf9eab48bd
         | 
| 4 | 
            +
              data.tar.gz: 159695c435f8f005dd5e0545d7cef2444cbf3875
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 462bdfa6e6320dd8cfc785128cc7dc80fe39396fd86e7ff62be92acead6daa57208cb377e1038231ab39c98a6f447b6b4bb60c40217ff91e831f454164f5702a
         | 
| 7 | 
            +
              data.tar.gz: 651d4fc2517d30dd48521a2ff9612b9f3bbf51123a8527d59f490d51695e4f4abc035c185a44d3022cfbd5b1d5505a40f1fbb4457b67166bbe31e5dbf3f1e984
         | 
| @@ -0,0 +1,185 @@ | |
| 1 | 
            +
            require 'jekyll'
         | 
| 2 | 
            +
            require 'liquid'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Jekyll
         | 
| 5 | 
            +
              module GitHubComments
         | 
| 6 | 
            +
                DEFAULTS = {
         | 
| 7 | 
            +
                  "branch" => "master",
         | 
| 8 | 
            +
                  "comments_template" => "comments.html",
         | 
| 9 | 
            +
                  "comment_template" => "comment.html"
         | 
| 10 | 
            +
                }
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                class Comments < Liquid::Block
         | 
| 13 | 
            +
                  def initialize(tag_name, markup, tokens)
         | 
| 14 | 
            +
                    super
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def parse(tokens)
         | 
| 18 | 
            +
                    super
         | 
| 19 | 
            +
                    @line = tokens[0].line_number
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  def render(context)
         | 
| 23 | 
            +
                    if context["subcomments"] then
         | 
| 24 | 
            +
                      context["comments"] = super
         | 
| 25 | 
            +
                    else
         | 
| 26 | 
            +
                      context["subcomments"] = true
         | 
| 27 | 
            +
                      context["comments"] = super
         | 
| 28 | 
            +
                      context["subcomments"] = false
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    config = DEFAULTS.merge(context["site"]["github_comments"] || {})
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    path = context["page"]["path"]
         | 
| 34 | 
            +
                    line_no = @line + context["page"]["yamlsize"] + 2
         | 
| 35 | 
            +
                    context["comment_url"] = 
         | 
| 36 | 
            +
                      "https://github.com/#{ config["repo"] }/edit/#{ config["branch"] }/#{ path }#L#{ line_no }"
         | 
| 37 | 
            +
                    
         | 
| 38 | 
            +
                    partial = Jekyll::Tags::IncludeTag.parse("include", config["comments_template"], [], @options)
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    context.stack do
         | 
| 41 | 
            +
                      partial.render(context)
         | 
| 42 | 
            +
                    end
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                class Comment < Liquid::Block
         | 
| 47 | 
            +
                  VALID_SYNTAX = %r!
         | 
| 48 | 
            +
                  ([\w-]+)\s*=\s*
         | 
| 49 | 
            +
                    (?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))
         | 
| 50 | 
            +
                  !x
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  def initialize(tag_name, markup, tokens)
         | 
| 53 | 
            +
                    super
         | 
| 54 | 
            +
                    @params = markup
         | 
| 55 | 
            +
                    full_valid_syntax = %r!\A\s*(?:#{VALID_SYNTAX}(?=\s|\z)\s*)*\z!
         | 
| 56 | 
            +
                      unless @params =~ full_valid_syntax
         | 
| 57 | 
            +
                        raise ArgumentError "Invalid syntax for comment tag: #{@params}"
         | 
| 58 | 
            +
                    end
         | 
| 59 | 
            +
                    @tag_name = tag_name
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  # Find threaded replies and store them separately to comment content
         | 
| 63 | 
            +
                  def parse(tokens)
         | 
| 64 | 
            +
                    @line = tokens[0].line_number
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                    @blank = true
         | 
| 67 | 
            +
                    @nodelist ||= []
         | 
| 68 | 
            +
                    @nodelist.clear
         | 
| 69 | 
            +
                    @replylist = []
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                    while token = tokens.shift
         | 
| 72 | 
            +
                      begin
         | 
| 73 | 
            +
                        unless token.empty?
         | 
| 74 | 
            +
                          case
         | 
| 75 | 
            +
                          when token.start_with?(TAGSTART)
         | 
| 76 | 
            +
                            if token =~ FullToken
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                              # if we found the proper block delimiter just end parsing here and let the outer block
         | 
| 79 | 
            +
                              # proceed
         | 
| 80 | 
            +
                              return if block_delimiter == $1
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                              if tag = Liquid::Template.tags[$1]
         | 
| 83 | 
            +
                                markup = token.is_a?(Liquid::Token) ? token.child($2) : $2
         | 
| 84 | 
            +
                                new_tag = tag.parse($1, markup, tokens, @options)
         | 
| 85 | 
            +
                                new_tag.line_number = token.line_number if token.is_a?(Liquid::Token)
         | 
| 86 | 
            +
                                if "responses" == $1
         | 
| 87 | 
            +
                                  @replylist << new_tag
         | 
| 88 | 
            +
                                else
         | 
| 89 | 
            +
                                  @blank &&= new_tag.blank?
         | 
| 90 | 
            +
                                  @nodelist << new_tag
         | 
| 91 | 
            +
                                end
         | 
| 92 | 
            +
                              else
         | 
| 93 | 
            +
                                # this tag is not registered with the system
         | 
| 94 | 
            +
                                # pass it to the current block for special handling or error reporting
         | 
| 95 | 
            +
                                unknown_tag($1, $2, tokens)
         | 
| 96 | 
            +
                              end
         | 
| 97 | 
            +
                            else
         | 
| 98 | 
            +
                              raise SyntaxError.new(options[:locale].t("errors.syntax.tag_termination".freeze, :token => token, :tag_end => TagEnd.inspect))
         | 
| 99 | 
            +
                            end
         | 
| 100 | 
            +
                          when token.start_with?(VARSTART)
         | 
| 101 | 
            +
                            new_var = create_variable(token)
         | 
| 102 | 
            +
                            new_var.line_number = token.line_number if token.is_a?(Liquid::Token)
         | 
| 103 | 
            +
                            @nodelist << new_var
         | 
| 104 | 
            +
                            @blank = false
         | 
| 105 | 
            +
                          else
         | 
| 106 | 
            +
                            @nodelist << token
         | 
| 107 | 
            +
                            @blank &&= (token =~ /\A\s*\z/)
         | 
| 108 | 
            +
                          end
         | 
| 109 | 
            +
                        end
         | 
| 110 | 
            +
                      rescue SyntaxError => e
         | 
| 111 | 
            +
                        e.set_line_number_from_token(token)
         | 
| 112 | 
            +
                        raise
         | 
| 113 | 
            +
                      end
         | 
| 114 | 
            +
                    end
         | 
| 115 | 
            +
                  end
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                  def parse_params(context)
         | 
| 118 | 
            +
                    params = {}
         | 
| 119 | 
            +
                    markup = @params
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                    while (match = VALID_SYNTAX.match(markup))
         | 
| 122 | 
            +
                      markup = markup[match.end(0)..-1]
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                      value = if match[2]
         | 
| 125 | 
            +
                                match[2].gsub(%r!\\"!, '"')
         | 
| 126 | 
            +
                              elsif match[3]
         | 
| 127 | 
            +
                                match[3].gsub(%r!\\'!, "'")
         | 
| 128 | 
            +
                              elsif match[4]
         | 
| 129 | 
            +
                                context[match[4]]
         | 
| 130 | 
            +
                              end
         | 
| 131 | 
            +
             | 
| 132 | 
            +
                      params[match[1]] = value
         | 
| 133 | 
            +
                    end
         | 
| 134 | 
            +
                    params
         | 
| 135 | 
            +
                  end
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                  # Remove leading whitespace to stop markdown treating it as code
         | 
| 138 | 
            +
                  def align_left(string)
         | 
| 139 | 
            +
                    return string if string.strip.size == 0
         | 
| 140 | 
            +
             | 
| 141 | 
            +
                    relevant_lines = string.split(/\r\n|\r|\n/).select { |line| line.strip.size > 0 }
         | 
| 142 | 
            +
                    indentation_levels = relevant_lines.map do |line|
         | 
| 143 | 
            +
                      match = line.match(/^( +)[^ ]+/)
         | 
| 144 | 
            +
                      match ? match[1].size : 0
         | 
| 145 | 
            +
                    end
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                    indentation_level = indentation_levels.min
         | 
| 148 | 
            +
                    string.gsub! /^#{' ' * indentation_level}/, '' if indentation_level > 0
         | 
| 149 | 
            +
                    string
         | 
| 150 | 
            +
                  end
         | 
| 151 | 
            +
             | 
| 152 | 
            +
                  def render(context)
         | 
| 153 | 
            +
                    config = DEFAULTS.merge(context["site"]["github_comments"] || {})
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                    comment = @params ? parse_params(context) : {}
         | 
| 156 | 
            +
                    comment["content"] = align_left(super)
         | 
| 157 | 
            +
                    comment["replies"] = render_all(@replylist, context) if @replylist.length 
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                    path = context["page"]["path"]
         | 
| 160 | 
            +
                    line_no = @line + context["page"]["yamlsize"] + 2
         | 
| 161 | 
            +
                    comment["reply_url"] = 
         | 
| 162 | 
            +
                      "https://github.com/#{ config["repo"] }/edit/#{ config["branch"] }/#{ path }#L#{ line_no }"
         | 
| 163 | 
            +
             | 
| 164 | 
            +
                    partial = Jekyll::Tags::IncludeTag.parse("include", config["comment_template"], [], @options)
         | 
| 165 | 
            +
             | 
| 166 | 
            +
                    context.stack do
         | 
| 167 | 
            +
                      context["comment"] = comment
         | 
| 168 | 
            +
                      partial.render(context)
         | 
| 169 | 
            +
                    end
         | 
| 170 | 
            +
                  end
         | 
| 171 | 
            +
                end
         | 
| 172 | 
            +
              end
         | 
| 173 | 
            +
            end
         | 
| 174 | 
            +
             | 
| 175 | 
            +
             | 
| 176 | 
            +
            Jekyll::Hooks.register [:posts, :pages, :documents], :pre_render do |page, payload|
         | 
| 177 | 
            +
              content = File.read(page.path)
         | 
| 178 | 
            +
              if content =~ Jekyll::Document::YAML_FRONT_MATTER_REGEXP
         | 
| 179 | 
            +
                yaml = Regexp.last_match(1)
         | 
| 180 | 
            +
              end
         | 
| 181 | 
            +
              payload.page["yamlsize"] = yaml ? yaml.lines.count : 0
         | 
| 182 | 
            +
            end
         | 
| 183 | 
            +
             | 
| 184 | 
            +
            Liquid::Template.register_tag('responses', Jekyll::GitHubComments::Comments)
         | 
| 185 | 
            +
            Liquid::Template.register_tag('response', Jekyll::GitHubComments::Comment)
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,72 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: jekyll-github-comments
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 1.0.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Steve Le Roy Harris
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2016-11-23 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: jekyll
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - ">="
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '3.0'
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - ">="
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '3.0'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: liquid
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '3.0'
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '3.0'
         | 
| 41 | 
            +
            description: A Jekyll plugin to provide static site comments via Github pull requests.
         | 
| 42 | 
            +
            email: steve@nourish.je
         | 
| 43 | 
            +
            executables: []
         | 
| 44 | 
            +
            extensions: []
         | 
| 45 | 
            +
            extra_rdoc_files: []
         | 
| 46 | 
            +
            files:
         | 
| 47 | 
            +
            - lib/jekyll-github-comments.rb
         | 
| 48 | 
            +
            homepage: http://rubygems.org/gems/jekyll-github-comments
         | 
| 49 | 
            +
            licenses:
         | 
| 50 | 
            +
            - MIT
         | 
| 51 | 
            +
            metadata: {}
         | 
| 52 | 
            +
            post_install_message: 
         | 
| 53 | 
            +
            rdoc_options: []
         | 
| 54 | 
            +
            require_paths:
         | 
| 55 | 
            +
            - lib
         | 
| 56 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 57 | 
            +
              requirements:
         | 
| 58 | 
            +
              - - ">="
         | 
| 59 | 
            +
                - !ruby/object:Gem::Version
         | 
| 60 | 
            +
                  version: '0'
         | 
| 61 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 62 | 
            +
              requirements:
         | 
| 63 | 
            +
              - - ">="
         | 
| 64 | 
            +
                - !ruby/object:Gem::Version
         | 
| 65 | 
            +
                  version: '0'
         | 
| 66 | 
            +
            requirements: []
         | 
| 67 | 
            +
            rubyforge_project: 
         | 
| 68 | 
            +
            rubygems_version: 2.5.1
         | 
| 69 | 
            +
            signing_key: 
         | 
| 70 | 
            +
            specification_version: 4
         | 
| 71 | 
            +
            summary: Jekyll Github Comments
         | 
| 72 | 
            +
            test_files: []
         |