Module: GollumRails::Core

Extended by:
ActiveSupport::Concern
Included in:
Page
Defined in:
lib/gollum_rails/core.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

ATTR_READERS =
[]
ATTR_WRITERS =
[:name, :content, :format]
ATTR_ACCESSORS =
[:commit, :gollum_page]

Instance Method Summary collapse

Instance Method Details

#canonicalized_filenameObject

Gets a canonicalized filename of the page


86
87
88
# File 'lib/gollum_rails/core.rb', line 86

def canonicalized_filename
  Gollum::Page.canonicalize_filename(name)
end

#cnameObject

:nodoc:


81
82
83
# File 'lib/gollum_rails/core.rb', line 81

def cname #:nodoc:
  Gollum::Page.cname(self.name)
end

#compare_commits(sha1, sha2 = nil) ⇒ Object

Compare 2 Commits.

sha1 - SHA1 sha2 - SHA1


154
155
156
# File 'lib/gollum_rails/core.rb', line 154

def compare_commits(sha1,sha2=nil)
  Page.wiki.full_reverse_diff_for(@gollum_page,sha1,sha2)
end

#contentObject


192
193
194
# File 'lib/gollum_rails/core.rb', line 192

def content
  @content ||= (@gollum_page.content || "")
end

#current_version(long = false) ⇒ Object

Gets the version of current commit


166
167
168
169
170
171
172
173
174
# File 'lib/gollum_rails/core.rb', line 166

def current_version(long=false)
  return nil unless persisted?
  unless long
    @gollum_page.version_short
  else
    @gollum_page.version.to_s
  end

end

#file_nameObject

:nodoc:


77
78
79
# File 'lib/gollum_rails/core.rb', line 77

def file_name #:nodoc:
  full_path.last
end

#filename(ext = true) ⇒ Object

Outputs the pages filename on disc

ext - Wether to output extension or not


188
189
190
# File 'lib/gollum_rails/core.rb', line 188

def filename(ext=true)
  @filename ||= (ext) ? @gollum_page.filename : @gollum_page.filename_stripped
end

#formatObject

Gets the pages format


177
178
179
# File 'lib/gollum_rails/core.rb', line 177

def format
  (@format || (@gollum_page.format||:markdown)).to_sym
end

#full_pathObject

:nodoc:


73
74
75
# File 'lib/gollum_rails/core.rb', line 73

def full_path #:nodoc:
  File.split(name)
end

#historyObject

Gets the history of current gollum_page

Returns an Array


138
139
140
141
# File 'lib/gollum_rails/core.rb', line 138

def history
  return nil unless persisted?
  gollum_page.versions
end

#html_dataObject

Gets formatted_data for current Gollum::Page

Returns a String


125
126
127
# File 'lib/gollum_rails/core.rb', line 125

def html_data
  gollum_page.formatted_data
end

#initialize(attrs = {}) {|_self| ... } ⇒ Object

Initializes a new Page

attrs - Hash of attributes

commit must be given to perform any page action!

Yields:

  • (_self)

Yield Parameters:


56
57
58
59
60
61
# File 'lib/gollum_rails/core.rb', line 56

def initialize(attrs = {})
  assign_attributes(attrs)
  _update_page_attributes if attrs[:gollum_page]
  yield self if block_given?
  run_callbacks :initialize unless _initialize_callbacks.empty?
end

#last_changed_byObject

Gets the last modified by Gollum::Committer

Returns a String


146
147
148
# File 'lib/gollum_rails/core.rb', line 146

def last_changed_by
  "%s <%s>" % [history.first.author.name, history.first.author.email]
end

#nameObject


181
182
183
# File 'lib/gollum_rails/core.rb', line 181

def name
  @name ||= (@gollum_page.name || "")
end

#path_nameObject

:nodoc:


67
68
69
70
71
# File 'lib/gollum_rails/core.rb', line 67

def path_name #:nodoc:
  f = full_path.first
  return '/' if f == '.'
  f
end

#preview(format = :markdown) ⇒ Object

Previews the page - Mostly used if you want to see what you do before saving

This is an extremely fast method! 1 rendering attempt take depending on the content about 0.001 (simple markdown) upto 0.004 (1000 chars markdown) seconds, which is quite good

format - Specify the format you want to render with see GollumRails::Core.selfself.format_supported?

for formats

Returns a String


101
102
103
104
# File 'lib/gollum_rails/core.rb', line 101

def preview(format=:markdown)
  require 'active_support/core_ext/string/output_safety'
  wiki.preview_page(name, content, format).formatted_data.html_safe
end

#raw_dataObject

Gets raw_data for current Gollum::Page

Returns a String


131
132
133
# File 'lib/gollum_rails/core.rb', line 131

def raw_data
  gollum_page.raw_data
end

#sub_page?Boolean

Checks if current page is a subpage

Returns:

  • (Boolean)

159
160
161
162
# File 'lib/gollum_rails/core.rb', line 159

def sub_page?
  return nil unless persisted?
  @gollum_page.sub_page
end

#titleObject

Gets the title for current Gollum::Page

Returns a String


118
119
120
# File 'lib/gollum_rails/core.rb', line 118

def title
  gollum_page.title
end

#to_paramObject


196
197
198
# File 'lib/gollum_rails/core.rb', line 196

def to_param
  name
end

#urlObject

Gets the url for current page from Gollum::Page

Returns a String


109
110
111
112
113
# File 'lib/gollum_rails/core.rb', line 109

def url
  if gollum_page
    gollum_page.url_path
  end
end

#url_pathObject

:nodoc:


63
64
65
# File 'lib/gollum_rails/core.rb', line 63

def url_path #:nodoc:
  File.split(url)
end