Class: Page
- Inherits:
-
Object
- Object
- Page
- Defined in:
- lib/wiki/page.rb
Overview
Page Class Handles writing and reading JSON data to and from files.
Instance Attribute Summary collapse
-
#default_directory ⇒ Object
Directory where default (pre-existing) pages are stored.
-
#directory ⇒ Object
Directory where pages are to be stored.
-
#plugins_directory ⇒ Object
Directory where plugins that may have pages are stored.
Instance Method Summary collapse
- #exists?(name) ⇒ Boolean
-
#get(name) ⇒ Hash
Get a page.
- #plugin_page_path(name) ⇒ Object
-
#put(name, page) ⇒ Hash
Create or update a page.
Instance Attribute Details
#default_directory ⇒ Object
Directory where default (pre-existing) pages are stored.
14 15 16 |
# File 'lib/wiki/page.rb', line 14 def default_directory @default_directory end |
#directory ⇒ Object
Directory where pages are to be stored.
12 13 14 |
# File 'lib/wiki/page.rb', line 12 def directory @directory end |
#plugins_directory ⇒ Object
Directory where plugins that may have pages are stored.
16 17 18 |
# File 'lib/wiki/page.rb', line 16 def plugins_directory @plugins_directory end |
Instance Method Details
#exists?(name) ⇒ Boolean
49 50 51 52 53 |
# File 'lib/wiki/page.rb', line 49 def exists?(name) Store.exists?(File.join(directory, name)) or File.exist?(File.join(default_directory, name)) or !plugin_page_path(name).nil? end |
#get(name) ⇒ Hash
Get a page
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/wiki/page.rb', line 31 def get(name) assert_attributes_set path = File.join(directory, name) default_path = File.join(default_directory, name) page = Store.get_page(path) if page page elsif File.exist?(default_path) FileStore.get_page(default_path) elsif (path = plugin_page_path name) page = FileStore.get_page(path) page['plugin'] = path.match(/plugins\/(.*?)\/pages/)[1] page else halt 404 end end |
#plugin_page_path(name) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/wiki/page.rb', line 18 def plugin_page_path name Dir.glob(File.join(plugins_directory, '*/pages')) do |dir| probe = "#{dir}/#{name}" return probe if File.exists? probe end return nil end |
#put(name, page) ⇒ Hash
Create or update a page
60 61 62 63 64 65 |
# File 'lib/wiki/page.rb', line 60 def put(name, page) assert_attributes_set path = File.join directory, name page.delete 'plugin' Store.put_page(path, page, :name => name, :directory => directory) end |