Class: Gollum::Filter::RemoteCode
- Inherits:
-
Gollum::Filter
- Object
- Gollum::Filter
- Gollum::Filter::RemoteCode
- 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```
Constant Summary
Constants inherited from Gollum::Filter
Instance Attribute Summary
Attributes inherited from Gollum::Filter
Instance Method Summary collapse
Methods inherited from Gollum::Filter
Methods included from Helpers
#path_to_link_text, #trim_leading_slashes
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 |
# File 'lib/gollum-lib/filter/remote_code.rb', line 15 def extract(data) 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.wiki.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
37 38 39 |
# File 'lib/gollum-lib/filter/remote_code.rb', line 37 def process(data) data end |