Class: Gollum::Markup
- Inherits:
-
Object
- Object
- Gollum::Markup
- Includes:
- Helpers
- Defined in:
- lib/gollum-lib/markup.rb,
lib/gollum-lib/markups.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#include_levels ⇒ Object
readonly
Returns the value of attribute include_levels.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sanitize ⇒ Object
readonly
Returns the value of attribute sanitize.
-
#to_xml_opts ⇒ Object
readonly
Returns the value of attribute to_xml_opts.
-
#toc ⇒ Object
Returns the value of attribute toc.
-
#wiki ⇒ Object
readonly
Returns the value of attribute wiki.
Class Method Summary collapse
-
.formats ⇒ Object
Only use the formats that are specified in config.rb.
-
.register(ext, name, options = {}, &block) ⇒ Object
Register a file extension and associated markup type.
Instance Method Summary collapse
-
#check_cache(type, id) ⇒ Object
Hook for getting the formatted value of extracted tag data.
-
#find_file(name, version = @version) ⇒ Object
Find the given file in the repo.
-
#initialize(page) ⇒ Markup
constructor
Initialize a new Markup object.
-
#render(no_follow = false, encoding = nil, include_levels = 10) ⇒ Object
Render the content with Gollum wiki syntax on top of the file’s own markup language.
-
#update_cache(type, id, data) ⇒ Object
Hook for caching the formatted value of extracted tag data.
Methods included from Helpers
Constructor Details
#initialize(page) ⇒ Markup
Initialize a new Markup object.
page - The Gollum::Page.
Returns a new Gollum::Markup object, ready for rendering.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gollum-lib/markup.rb', line 60 def initialize(page) @wiki = page.wiki @name = page.filename @data = page.text_data @version = page.version.id if page.version @format = page.format @sub_page = page.sub_page @parent_page = page.parent_page @dir = ::File.dirname(page.path) = nil @to_xml_opts = { :save_with => Nokogiri::XML::Node::SaveOptions::DEFAULT_XHTML ^ 1, :indent => 0, :encoding => 'UTF-8' } end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
53 54 55 |
# File 'lib/gollum-lib/markup.rb', line 53 def dir @dir end |
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
46 47 48 |
# File 'lib/gollum-lib/markup.rb', line 46 def encoding @encoding end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
48 49 50 |
# File 'lib/gollum-lib/markup.rb', line 48 def format @format end |
#include_levels ⇒ Object (readonly)
Returns the value of attribute include_levels.
51 52 53 |
# File 'lib/gollum-lib/markup.rb', line 51 def include_levels @include_levels end |
#metadata ⇒ Object
Returns the value of attribute metadata.
45 46 47 |
# File 'lib/gollum-lib/markup.rb', line 45 def end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
50 51 52 |
# File 'lib/gollum-lib/markup.rb', line 50 def name @name end |
#sanitize ⇒ Object (readonly)
Returns the value of attribute sanitize.
47 48 49 |
# File 'lib/gollum-lib/markup.rb', line 47 def sanitize @sanitize end |
#to_xml_opts ⇒ Object (readonly)
Returns the value of attribute to_xml_opts.
52 53 54 |
# File 'lib/gollum-lib/markup.rb', line 52 def to_xml_opts @to_xml_opts end |
#toc ⇒ Object
Returns the value of attribute toc.
44 45 46 |
# File 'lib/gollum-lib/markup.rb', line 44 def toc @toc end |
#wiki ⇒ Object (readonly)
Returns the value of attribute wiki.
49 50 51 |
# File 'lib/gollum-lib/markup.rb', line 49 def wiki @wiki end |
Class Method Details
.formats ⇒ Object
Only use the formats that are specified in config.rb
19 20 21 22 23 24 25 |
# File 'lib/gollum-lib/markup.rb', line 19 def formats if defined? Gollum::Page::FORMAT_NAMES @formats.select { |_, value| Gollum::Page::FORMAT_NAMES.values.include? value[:name] } else @formats end end |
.register(ext, name, options = {}, &block) ⇒ Object
Register a file extension and associated markup type
ext - The file extension name - The name of the markup type options - Hash of options:
regexp - Regexp to match against.
Defaults to exact match of ext.
If given a block, that block will be registered with GitHub::Markup to render any matching pages
37 38 39 40 41 |
# File 'lib/gollum-lib/markup.rb', line 37 def register(ext, name, = {}, &block) regexp = [:regexp] || Regexp.new(ext.to_s) @formats[ext] = { :name => name, :regexp => regexp } GitHub::Markup.add_markup(regexp, &block) if block_given? end |
Instance Method Details
#check_cache(type, id) ⇒ Object
Hook for getting the formatted value of extracted tag data.
type - Symbol value identifying what type of data is being extracted. id - String SHA1 hash of original extracted tag data.
Returns the String cached formatted data, or nil.
139 140 |
# File 'lib/gollum-lib/markup.rb', line 139 def check_cache(type, id) end |
#find_file(name, version = @version) ⇒ Object
Find the given file in the repo.
name - The String absolute or relative path of the file.
Returns the Gollum::File or nil if none was found.
124 125 126 127 128 129 130 131 |
# File 'lib/gollum-lib/markup.rb', line 124 def find_file(name, version=@version) if name =~ /^\// @wiki.file(name[1..-1], version) else path = @dir == '.' ? name : ::File.join(@dir, name) @wiki.file(path, version) end end |
#render(no_follow = false, encoding = nil, include_levels = 10) ⇒ Object
Render the content with Gollum wiki syntax on top of the file’s own markup language.
no_follow - Boolean that determines if rel=“nofollow” is added to all
<a> .
encoding - Encoding Constant or String.
Returns the formatted String content.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/gollum-lib/markup.rb', line 81 def render(no_follow = false, encoding = nil, include_levels = 10) @sanitize = no_follow ? @wiki.history_sanitizer : @wiki.sanitizer @encoding = encoding @include_levels = include_levels data = @data.dup filter_chain = @wiki.filter_chain.map do |r| Gollum::Filter.const_get(r).new(self) end # Since the last 'extract' action in our chain *should* be the markup # to HTML converter, we now have HTML which we can parse and yield, for # anyone who wants it if block_given? yield Nokogiri::HTML::DocumentFragment.parse(data) end # First we extract the data through the chain... filter_chain.each do |filter| data = filter.extract(data) end # Then we process the data through the chain *backwards* filter_chain.reverse.each do |filter| data = filter.process(data) end # Finally, a little bit of cleanup, just because data.gsub!(/<p><\/p>/) do '' end data end |
#update_cache(type, id, data) ⇒ Object
Hook for caching the formatted value of extracted tag data.
type - Symbol value identifying what type of data is being extracted. id - String SHA1 hash of original extracted tag data. data - The String formatted value to be cached.
Returns nothing.
149 150 |
# File 'lib/gollum-lib/markup.rb', line 149 def update_cache(type, id, data) end |