Module: GollumRails::Core

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

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#canonicalized_filenameObject



51
52
53
# File 'lib/gollum_rails/core.rb', line 51

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

#compare_commits(sha1, sha2 = nil) ⇒ Object

Compare 2 Commits.

sha1 - SHA1 sha2 - SHA1



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

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

#current_version(long = false) ⇒ Object

Gets the version of current commit



139
140
141
142
143
144
145
146
147
# File 'lib/gollum_rails/core.rb', line 139

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

#historyObject

Gets the history of current gollum_page

Returns an Array



103
104
105
106
# File 'lib/gollum_rails/core.rb', line 103

def history
  return nil unless persisted?
  gollum_page.versions
end

#html_dataObject

Gets formatted_data for current Gollum::Page

Returns a String



90
91
92
# File 'lib/gollum_rails/core.rb', line 90

def html_data
  gollum_page.formatted_data
end

#initialize(attrs = {}) ⇒ Object

Initializes a new Page

attrs - Hash of attributes

commit must be given to perform any page action!



33
34
35
36
37
38
39
40
# File 'lib/gollum_rails/core.rb', line 33

def initialize(attrs = {})
  run_callbacks :initialize do
    if wiki
      attrs.each{|k,v| self.public_send("#{k}=",v)} if attrs
      update_attrs if attrs[:gollum_page]
    end
  end
end

#last_changed_byObject

Gets the last modified by Gollum::Committer

Returns a String



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

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

#path_nameObject



44
45
46
47
48
# File 'lib/gollum_rails/core.rb', line 44

def path_name
  f = File.split(name).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



66
67
68
# File 'lib/gollum_rails/core.rb', line 66

def preview(format=:markdown)
  wiki.preview_page(name, content, format).formatted_data
end

#raw_dataObject

Gets raw_data for current Gollum::Page

Returns a String



96
97
98
# File 'lib/gollum_rails/core.rb', line 96

def raw_data
  gollum_page.raw_data
end

#sub_page?Boolean

Checks if current page is a subpage

Returns:

  • (Boolean)


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

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

#titleObject

Gets the title for current Gollum::Page

Returns a String



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

def title
  gollum_page.title
end

#urlObject

Gets the url for current page from Gollum::Page

Returns a String



75
76
77
# File 'lib/gollum_rails/core.rb', line 75

def url
  gollum_page.url_path
end