Class: Gollum::Filter::RemoteCode

Inherits:
Gollum::Filter show all
Defined in:
lib/gollum-lib/filter/remote_code.rb

Overview

Remote code - fetch code from url and replace the contents to a

    code-block that gets run the next parse.
Acceptable formats:
   ```language:local-file.ext```
   ```language:/abs/other-file.ext```
   ```language:https://example.com/somefile.txt```

Instance Method Summary collapse

Methods inherited from Gollum::Filter

#initialize

Methods included from Helpers

#trim_leading_slash

Constructor Details

This class inherits a constructor from Gollum::Filter

Instance Method Details

#extract(data) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gollum-lib/filter/remote_code.rb', line 15

def extract(data)
  return data if @markup.format == :txt
  data.gsub(/^[ \t]*``` ?([^:\n\r]+):((http)?[^`\n\r]+)```/) do
    language = Regexp.last_match[1]
    uri      = Regexp.last_match[2]
    protocol = Regexp.last_match[3]

    # Detect local file
    if protocol.nil?
      if (file = @markup.find_file(uri, @markup.wiki.ref))
        contents = file.raw_data
      else
        # How do we communicate a render error?
        next html_error("File not found: #{CGI::escapeHTML(uri)}")
      end
    else
      contents = req(uri)
    end

    "```#{language}\n#{contents}\n```\n"
  end
end

#process(data) ⇒ Object



38
39
40
# File 'lib/gollum-lib/filter/remote_code.rb', line 38

def process(data)
  data
end