class Rwiki::Page
Attributes
file_helper[R]
textile_helper[R]
Public Class Methods
fuzzy_finder(query)
click to toggle source
TODO cleanup and write tests
# File lib/rwiki/page.rb, line 133 def self.fuzzy_finder(query) @finder ||= FuzzyFileFinder.new(Rwiki.configuration.rwiki_path) @finder.rescan! matches = @finder.find(query).sort_by { |m| [-m[:score], m[:path]] } matches.each do |m| m[:path] = m[:path].gsub(Rwiki.configuration.rwiki_path, '').gsub(/\.#{Rwiki.configuration.page_file_extension}$/, '') m[:highlighted_path] = m[:highlighted_path].gsub(/\.#{Rwiki.configuration.page_file_extension}$/, '') end matches end
new(path = Rwiki.configuration.root_page_name)
click to toggle source
# File lib/rwiki/page.rb, line 14 def initialize(path = Rwiki.configuration.root_page_name) @file_helper = FileHelper.new(path) raise Error.new("Cannot find the #{path} page") unless file_helper.exists? end
root()
click to toggle source
# File lib/rwiki/page.rb, line 10 def self.root self.new end
Protected Class Methods
fetch_children(full_path)
click to toggle source
# File lib/rwiki/page.rb, line 168 def self.fetch_children(full_path) children = [] if Dir.exists?(full_path) files = Dir.glob("#{full_path}/*.txt").sort files.each do |file| children << Page.new(file) end end children end
Public Instance Methods
add_page(name)
click to toggle source
# File lib/rwiki/page.rb, line 76 def add_page(name) Page.new(file_helper.add_page(name)) end
children()
click to toggle source
# File lib/rwiki/page.rb, line 48 def children @children ||= fetch_children end
delete()
click to toggle source
# File lib/rwiki/page.rb, line 107 def delete raise Error.new("Cannot delete the #{Rwiki.configuration.root_page_name} page") if is_root? file_helper.delete end
file_content()
click to toggle source
# File lib/rwiki/page.rb, line 80 def file_content @file_content ||= file_helper.read_file_content end
findgrep(pattern, matches = [])
click to toggle source
# File lib/rwiki/page.rb, line 146 def findgrep(pattern, matches = []) pattern = /#{Regexp.escape(pattern)}/i if pattern.kind_of?(String) children.each do |child| child.file_content.lines.grep(pattern) do |line| matches << { :path => child.path, :line => line.strip } end if child.has_children? child.findgrep(pattern, matches) end end matches end
full_file_path()
click to toggle source
# File lib/rwiki/page.rb, line 35 def full_file_path file_helper.full_file_path end
full_path()
click to toggle source
# File lib/rwiki/page.rb, line 31 def full_path file_helper.full_path end
has_children?()
click to toggle source
# File lib/rwiki/page.rb, line 56 def has_children? !leaf? end
html_content()
click to toggle source
# File lib/rwiki/page.rb, line 84 def html_content @html_content ||= textile_helper.parsed_content end
html_toc()
click to toggle source
# File lib/rwiki/page.rb, line 88 def html_toc @html_toc ||= textile_helper.parsed_toc end
is_root?()
click to toggle source
# File lib/rwiki/page.rb, line 23 def is_root? file_helper.path == Rwiki.configuration.root_page_path end
leaf?()
click to toggle source
# File lib/rwiki/page.rb, line 52 def leaf? children.size == 0 end
move_to(node)
click to toggle source
# File lib/rwiki/page.rb, line 102 def move_to(node) raise Error.new("Cannot move the #{Rwiki.configuration.root_page_name} page") if is_root? file_helper.move_to(node.path) end
parent()
click to toggle source
# File lib/rwiki/page.rb, line 43 def parent return if is_root? @parent ||= Page.new(file_helper.full_parent_path) end
path()
click to toggle source
# File lib/rwiki/page.rb, line 27 def path file_helper.path end
rename_to(new_name)
click to toggle source
# File lib/rwiki/page.rb, line 97 def rename_to(new_name) raise Error.new("Cannot rename the #{Rwiki.configuration.root_page_name} page") if is_root? file_helper.rename_to(new_name) end
title()
click to toggle source
# File lib/rwiki/page.rb, line 39 def title file_helper.basename end
to_hash()
click to toggle source
# File lib/rwiki/page.rb, line 119 def to_hash { :path => path, :rawContent => file_content, :htmlContent => html_content, :htmlToc => html_toc } end
to_json(extra_attrs = {})
click to toggle source
# File lib/rwiki/page.rb, line 128 def to_json(extra_attrs = {}) to_hash.merge(extra_attrs).to_json end
to_tree_node_hash()
click to toggle source
# File lib/rwiki/page.rb, line 112 def to_tree_node_hash { :text => title, :leaf => false } end
tree()
click to toggle source
# File lib/rwiki/page.rb, line 60 def tree result = [] children.each do |child| tree_node = child.to_tree_node_hash if child.has_children? tree_node[:children] = child.tree end result << tree_node end result end
update_file_content(file_content)
click to toggle source
# File lib/rwiki/page.rb, line 92 def update_file_content(file_content) file_helper.update_file_content(file_content) reload! end
Protected Instance Methods
fetch_children()
click to toggle source
# File lib/rwiki/page.rb, line 164 def fetch_children self.class.fetch_children(full_path) end
reload!()
click to toggle source
# File lib/rwiki/page.rb, line 181 def reload! @parent = nil @children = nil @file_content = nil @html_content = nil end