Permalink
Browse files

added bit of page model

  • Loading branch information...
1 parent d413371 commit f06ed6c9dae54c6909bf4b203cbc0bdc40ed018e @mkdynamic committed Nov 16, 2008
Showing with 65 additions and 6 deletions.
  1. +2 −1 .gitignore
  2. +50 −0 app/models/page.rb
  3. +3 −3 config/database.yml
  4. +3 −0 config/init.rb
  5. +7 −2 lib/backpack.rb
View
@@ -15,4 +15,5 @@ schema/*.db
src/*
.hgignore
.hg/*
-.svn/*
+.svn/*
+config/backpack.yml
View
@@ -0,0 +1,50 @@
+class Page
+
+ attr_accessor :id, :title,
+ attr_accessor :tags, :widgets, :parent
+ attr_accessor :bp_data
+
+ class << self
+ def find(id)
+ bp_data = Backpack.interface.show_page(id)
+ Page.new(id, bp_data)
+ end
+
+ def find_by_trail(trail)
+ pages = Backpack.interface.list_pages['pages'].first['page']
+ if (p = pages.find { |p| p['title'].strip == trail })
+ Page.find(p['id'].to_i)
+ else
+ return nil
+ end
+ end
+ end
+
+ def initialize(id, bp_data)
+ @id, @bp_data = id, bp_data
+ end
+
+ def title
+ load_title unless @title
+ @title
+ end
+
+ def parent
+ load_parent unless @parent
+ @parent
+ end
+
+ # backpack data loaders
+ def load_title
+ bp_title = bp_data['page'].first['title']
+ @title = bp_title.split('>').last.strip
+ end
+
+ def load_parent
+ bp_title = bp_data['page'].first['title']
+ trail = bp_title.split('>')
+ trail.pop # remove this page title
+ @parent = Page.find_by_trail(trail.join('>').strip)
+ end
+
+end
View
@@ -3,7 +3,7 @@
development: &defaults
# These are the settings for repository :default
adapter: sqlite3
- database: sample_development.db
+ database: db/development.db
# Add more repositories
# repositories:
@@ -15,15 +15,15 @@ development: &defaults
test:
<<: *defaults
- database: sample_test.db
+ database: db/test.db
# repositories:
# repo1:
# database: sample_1_test.db
production:
<<: *defaults
- database: production.db
+ database: db/production.db
# repositories:
# repo1:
View
@@ -21,4 +21,7 @@
Merb::BootLoader.after_app_loads do
# This will get executed after your app's classes have been loaded.
+ require 'backpack'
end
+
+
View
@@ -6,9 +6,14 @@
class Backpack
attr_accessor :username, :token, :current_page_id
+
+ def self.interface
+ @@interface ||= Backpack.new
+ end
- def initialize(username, token)
- @username, @token = username, token
+ def initialize
+ config = YAML::load_file(Merb.root_path('config/backpack.yml'))
+ @username, @token = config['username'], config['token']
connect
end

0 comments on commit f06ed6c

Please sign in to comment.