module GollumRails::Core

Constants

ATTR_ACCESSORS
ATTR_READERS
ATTR_WRITERS

Public Class Methods

new(attrs = {}) { |self| ... } click to toggle source

Initializes a new Page

attrs - Hash of attributes

commit must be given to perform any page action!

# 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

Public Instance Methods

canonicalized_filename() click to toggle source

Gets a canonicalized filename of the page

# File lib/gollum_rails/core.rb, line 86
def canonicalized_filename
  Gollum::Page.canonicalize_filename(name)
end
compare_commits(sha1,sha2=nil) click to toggle source

Compare 2 Commits.

sha1 - SHA1 sha2 - SHA1

# 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
content() click to toggle source
# File lib/gollum_rails/core.rb, line 192
def content
  @content ||= (@gollum_page.content || "")
end
current_version(long=false) click to toggle source

Gets the version of current commit

# 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
filename(ext=true) click to toggle source

Outputs the pages filename on disc

ext - Wether to output extension or not

# File lib/gollum_rails/core.rb, line 188
def filename(ext=true)
  @filename ||= (ext) ? @gollum_page.filename : @gollum_page.filename_stripped
end
format() click to toggle source

Gets the pages format

# File lib/gollum_rails/core.rb, line 177
def format
  (@format || (@gollum_page.format||:markdown)).to_sym
end
history() click to toggle source

Gets the history of current gollum_page

Returns an Array

# File lib/gollum_rails/core.rb, line 138
def history
  return nil unless persisted?
  gollum_page.versions
end
html_data() click to toggle source

Gets formatted_data for current Gollum::Page

Returns a String

# File lib/gollum_rails/core.rb, line 125
def html_data
  gollum_page.formatted_data
end
last_changed_by() click to toggle source

Gets the last modified by Gollum::Committer

Returns a String

# File lib/gollum_rails/core.rb, line 146
def last_changed_by
  "%s <%s>" % [history.first.author.name, history.first.author.email]
end
name() click to toggle source
# File lib/gollum_rails/core.rb, line 181
def name
  @name ||= (@gollum_page.name || "")
end
preview(format=:markdown) click to toggle source

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 {self.format_supported?}

for formats

Returns a String

# 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_data() click to toggle source

Gets raw_data for current Gollum::Page

Returns a String

# File lib/gollum_rails/core.rb, line 131
def raw_data
  gollum_page.raw_data
end
sub_page?() click to toggle source

Checks if current page is a subpage

# File lib/gollum_rails/core.rb, line 159
def sub_page?
  return nil unless persisted?
  @gollum_page.sub_page
end
title() click to toggle source

Gets the title for current Gollum::Page

Returns a String

# File lib/gollum_rails/core.rb, line 118
def title
  gollum_page.title
end
to_param() click to toggle source
# File lib/gollum_rails/core.rb, line 196
def to_param
  name
end
url() click to toggle source

Gets the url for current page from Gollum::Page

Returns a String

# File lib/gollum_rails/core.rb, line 109
def url
  if gollum_page
    gollum_page.url_path
  end
end

Private Instance Methods

_update_page_attributes() click to toggle source

Updates local attributes from gollum_page class

# File lib/gollum_rails/core.rb, line 215
def _update_page_attributes
  @name = gollum_page.name
  @content= gollum_page.raw_data
  @format = gollum_page.format
end
get_right_commit(commit_local) click to toggle source

Gets the right commit out of 2 commits

commit_local - local commit Hash

Returns local_commit > class_commit

# File lib/gollum_rails/core.rb, line 207
def get_right_commit(commit_local)
  com = commit if commit_local.nil?
  com = commit_local if !commit_local.nil?
  return com
end