manuscript 0.1.11 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.11
1
+ 0.2.0
@@ -0,0 +1,9 @@
1
+ class AddParentToPages < ActiveRecord::Migration
2
+ def self.up
3
+ add_column "pages", "parent_id", "integer"
4
+ end
5
+
6
+ def self.down
7
+ remove_column "pages", "parent_id"
8
+ end
9
+ end
data/lib/manuscript.rb CHANGED
@@ -22,7 +22,6 @@ require 'manuscript/user'
22
22
 
23
23
 
24
24
  log = File.new("application.log", "a")
25
- $stdout.reopen(log)
26
25
  $stderr.reopen(log)
27
26
  LOGGER = Logger.new($stderr)
28
27
  ActiveRecord::Base.logger = LOGGER
@@ -1,18 +1,21 @@
1
1
  module Manuscript
2
2
  class Base < Sinatra::Base
3
- get "/:page_name" do
4
- @user = session[:sso].nil? ? nil : User.new(session[:sso])
5
- @page = Page.find_by_name(params[:page_name])
6
- raise Sinatra::NotFound unless @page
7
- @page.to_html(@user)
8
- end
9
-
10
3
  get "/" do
11
4
  @user = session[:sso].nil? ? nil : User.new(session[:sso])
12
5
  @page = Page.find_by_name('index')
13
6
  raise Sinatra::NotFound unless @page
14
7
  @page.to_html(@user)
15
8
  end
16
-
9
+
10
+ get %r{/([-\w/]+)} do
11
+ begin
12
+ @user = session[:sso].nil? ? nil : User.new(session[:sso])
13
+ @page = Page.find_by_path(params[:captures].first)
14
+ raise Sinatra::NotFound unless @page
15
+ @page.to_html(@user)
16
+ rescue ActiveRecord::RecordNotFound
17
+ raise Sinatra::NotFound
18
+ end
19
+ end
17
20
  end
18
21
  end
@@ -8,7 +8,42 @@ module Manuscript
8
8
  validates_presence_of :name
9
9
  validates_uniqueness_of :name
10
10
  validates_format_of :name, :with => /^[-a-zA-Z0-9]+$/
11
+
12
+ belongs_to :parent, :class_name => "Page"
13
+ has_many :child_pages, :class_name => "Page", :foreign_key => "parent_id", :order => :name
14
+ named_scope :main_pages, :conditions => { :parent_id => nil }
11
15
 
16
+ def self.find_by_path(path)
17
+ page_names = path.split("/")
18
+ LOGGER.info("manuscript --> path: " + path.to_s)
19
+ LOGGER.info("manuscript --> page_names: " + page_names.inspect)
20
+ @page = self.main_pages.find_by_name(page_names.delete_at(0))
21
+ raise ActiveRecord::RecordNotFound unless @page
22
+ unless page_names.blank?
23
+ page_names.each do |page_name|
24
+ @page = @page.child_pages.find_by_name(page_name)
25
+ raise ActiveRecord::RecordNotFound unless @page
26
+ end
27
+ end
28
+ @page
29
+ end
30
+
31
+ def url
32
+ if parent
33
+ "#{parent.url}/#{name}"
34
+ else
35
+ "/#{name}"
36
+ end
37
+ end
38
+
39
+ def parent_url
40
+ if parent
41
+ parent.url
42
+ else
43
+ ""
44
+ end
45
+ end
46
+
12
47
  def to_html(user = nil)
13
48
  if template
14
49
  template.render({'current_user' => user, 'contents' => RDiscount.new(contents).to_html})
@@ -8,13 +8,13 @@ module Manuscript
8
8
  end
9
9
 
10
10
  get "/admin/pages/?" do
11
- @pages = Page.all
11
+ @pages = Page.main_pages.all
12
12
  haml :pages
13
13
  end
14
14
 
15
15
  get "/admin/pages/new" do
16
16
  @templates = Manuscript::PageTemplate.all
17
- @page = Page.new
17
+ @page = Page.new(:parent_id => params[:parent_id])
18
18
  haml :page
19
19
  end
20
20
 
@@ -36,6 +36,13 @@ module Manuscript
36
36
  @page.update_attributes!(params[:page])
37
37
  redirect "/admin/pages/#{@page.id}/edit"
38
38
  end
39
+
40
+ delete '/admin/pages/:id' do
41
+ @page = Page.find_by_id params[:id]
42
+ raise Sinatra::NotFound unless @page
43
+ @page.destroy
44
+ redirect '/admin/pages'
45
+ end
39
46
  end
40
47
 
41
48
  end
data/manuscript.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{manuscript}
8
- s.version = "0.1.11"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["hotink"]
12
- s.date = %q{2010-01-21}
12
+ s.date = %q{2010-01-22}
13
13
  s.description = %q{A gem for publishing a small Hot Ink authenticated site}
14
14
  s.email = %q{chris@hotink.net}
15
15
  s.extra_rdoc_files = [
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "db/migrate/003_add_template_id_to_pages.rb",
30
30
  "db/migrate/004_add_layouts_to_templates.rb",
31
31
  "db/migrate/005_create_template_files.rb",
32
+ "db/migrate/006_add_parent_to_pages.rb",
32
33
  "lib/manuscript.rb",
33
34
  "lib/manuscript/base.rb",
34
35
  "lib/manuscript/keymaster.rb",
@@ -54,6 +55,7 @@ Gem::Specification.new do |s|
54
55
  "spec/manuscript/user_spec.rb",
55
56
  "spec/spec.opts",
56
57
  "spec/spec_helper.rb",
58
+ "views/_page.haml",
57
59
  "views/edit_template_file.haml",
58
60
  "views/layout.haml",
59
61
  "views/menu.haml",
data/public/css/base.css CHANGED
@@ -1,13 +1,20 @@
1
1
  body { font-size: 16px; color: #222; line-height: 1.1em; margin:0; font-family: "Helvetica Neue", verdana, tahoma, arial, sans-serif; }
2
2
  div#page_container { width: 960px; margin: 5px 10px; }
3
3
 
4
+ ol#pages small { font-size: 65%;}
5
+ ol#pages small a { text-decoration: none; font-weight: 200;}
6
+
4
7
  ol.menu { list-style: none; padding: 5px; margin-top: 0; background-color: #FFF6DD; }
5
8
  ol.menu li { display: inline; margin: 0 10px; }
6
9
  ol.menu li a { text-decoration: none; }
7
10
  ol.menu li a.current { font-weight: bold; text-decoration: underline; }
8
11
 
12
+ ol#pages small { font-size: 65%;}
13
+ ol#pages small a { text-decoration: none; }
14
+
9
15
  ol#pages { list-style: none; font-size: 20px; margin: 30px 0; }
10
- ol#pages li { margin: 15px 0;}
16
+ ol#pages ol { list-style: none; font-size: 20px; margin: 10px 0; }
17
+ ol#pages li { margin: 15px 0; font-weight: bold; }
11
18
 
12
19
  form label { display:block; padding: 10px 0; }
13
20
  form input[type="text"] { font-size: 20px; width: 600px; border: 1px solid #AAA; padding: 3px; }
@@ -21,4 +21,14 @@ describe Manuscript::Base do
21
21
  get "/#{@page.name.reverse}"
22
22
  last_response.should be_not_found
23
23
  end
24
+
25
+ it "should only display child pages beneath their parents" do
26
+ new_page = Manuscript::Page.create!(:name => "child", :parent_id => @page.id, :contents => "Here are some **Sample issue contents**." )
27
+
28
+ get "/#{new_page.name}"
29
+ last_response.should be_not_found
30
+
31
+ get "/#{@page.name}/#{new_page.name}"
32
+ last_response.should be_ok
33
+ end
24
34
  end
@@ -9,28 +9,43 @@ describe "PageManager" do
9
9
 
10
10
  describe "when there are two pages" do
11
11
  before do
12
- @pages = Manuscript::Page.create([{:name => "index", :contents => "Page 1"}, {:name => "contact", :contents => "Page 2"}])
12
+ @pages = Manuscript::Page.create([{:name => "details", :contents => "Page 1"}, {:name => "contact", :contents => "Page 2"}])
13
13
  end
14
14
 
15
15
  it "should display list with both pages" do
16
16
  get "/admin/pages"
17
17
 
18
18
  last_response.should be_ok
19
- last_response.body.should include("index")
19
+ last_response.body.should include("details")
20
20
  last_response.body.should include("contact")
21
21
  end
22
22
 
23
- it "should allow new page to be created" do
24
- get "/admin/pages/new"
25
- last_response.should be_ok
23
+ describe "creating a new page" do
24
+ it "should allow new top-level page to be created" do
25
+ get "/admin/pages/new"
26
+ last_response.should be_ok
26
27
 
27
- post "/admin/pages", :page => { :name => "new-page", :contents => "New page contents" }
28
- last_response.should be_redirect
29
- follow_redirect!
30
- last_response.should be_ok
31
- last_response.body.should include("New page contents")
28
+ post "/admin/pages", :page => { :name => "new-page", :contents => "New page contents" }
29
+ last_response.should be_redirect
30
+ follow_redirect!
31
+ last_response.should be_ok
32
+ last_response.body.should include("New page contents")
33
+ end
34
+
35
+ it "should allow a new child-page to be created" do
36
+ parent = @pages.first
37
+ get "/admin/pages/new", :parent_id => parent.id
38
+ last_response.should be_ok
39
+ last_response.body.should include(parent.name)
40
+
41
+ post "/admin/pages", :page => { :name => "new-page", :contents => "New page contents", :parent_id => parent.id }
42
+ last_response.should be_redirect
43
+ follow_redirect!
44
+ last_response.should be_ok
45
+ last_response.body.should include(parent.name)
46
+ end
32
47
  end
33
-
48
+
34
49
  it "should allow pages to be edited" do
35
50
  page = Manuscript::Page.first
36
51
  get "/admin/pages/#{page.id}/edit"
@@ -43,6 +58,15 @@ describe "PageManager" do
43
58
  last_response.should be_ok
44
59
  last_response.body.should include("Changed page contents")
45
60
  end
61
+
62
+ it "should allow pages to be deleted" do
63
+ page = Manuscript::Page.first
64
+ delete "/admin/pages/#{page.id}"
65
+ last_response.should be_redirect
66
+
67
+ get "/admin/pages/#{page.id}/edit"
68
+ last_response.should be_not_found
69
+ end
46
70
  end
47
71
 
48
72
  end
@@ -4,10 +4,58 @@ describe Manuscript::Page do
4
4
 
5
5
  subject { Manuscript::Page.create!(:name => 'words', :contents => 'we got em') }
6
6
 
7
+ it { should belong_to(:parent) }
7
8
  it { should validate_presence_of(:name) }
8
9
  it { should validate_uniqueness_of(:name) }
9
10
  it { should belong_to(:template) }
10
11
 
12
+ it "should identify top-level pages" do
13
+ page1 = Manuscript::Page.create!(:name => 'top-level1', :contents => 'we got it')
14
+ page2 = Manuscript::Page.create!(:name => 'top-level2', :contents => 'we got it')
15
+ child1 = Manuscript::Page.create!(:name => 'child1', :contents => 'we got it', :parent => page1)
16
+ child2 = Manuscript::Page.create!(:name => 'child2', :contents => 'we got it', :parent => page1)
17
+ grandchild1 = Manuscript::Page.create!(:name => 'grandchild2', :contents => 'we got it', :parent => child1)
18
+
19
+ Manuscript::Page.main_pages.should include(page1)
20
+ Manuscript::Page.main_pages.should include(page1)
21
+ Manuscript::Page.main_pages.should_not include(child1)
22
+ Manuscript::Page.main_pages.should_not include(child2)
23
+ Manuscript::Page.main_pages.should_not include(grandchild1)
24
+ end
25
+
26
+ it "should know what it's child pages are" do
27
+ parent1 = Manuscript::Page.create!(:name => 'top-level1', :contents => 'we got it')
28
+ parent2 = Manuscript::Page.create!(:name => 'top-level2', :contents => 'we got it')
29
+ child1 = Manuscript::Page.create!(:name => 'child1', :contents => 'we got it', :parent => parent1)
30
+ child2 = Manuscript::Page.create!(:name => 'child2', :contents => 'we got it', :parent => parent1)
31
+ grandchild1 = Manuscript::Page.create!(:name => 'grandchild2', :contents => 'we got it', :parent => child1)
32
+
33
+ parent1.child_pages.should include(child1)
34
+ parent1.child_pages.should include(child2)
35
+
36
+ parent1.child_pages.should_not include(parent2)
37
+ parent1.child_pages.should_not include(grandchild1)
38
+ end
39
+
40
+ it "should know it's url" do
41
+ page1 = Manuscript::Page.create!(:name => 'some', :contents => 'we got em')
42
+ page2 = Manuscript::Page.create!(:name => 'things', :contents => 'we got em', :parent => page1)
43
+ page3 = Manuscript::Page.create!(:name => 'youneed', :contents => 'we got em', :parent => page2)
44
+
45
+ page1.url.should == "/some"
46
+ page3.url.should == "/some/things/youneed"
47
+ end
48
+
49
+ it "should find child pages by path" do
50
+ page1 = Manuscript::Page.create!(:name => 'one', :contents => 'we got one')
51
+ page2 = Manuscript::Page.create!(:name => 'two', :contents => 'we got two', :parent => page1)
52
+ page3 = Manuscript::Page.create!(:name => 'three', :contents => 'we got three', :parent => page2)
53
+
54
+ Manuscript::Page.find_by_path("#{page1.name}").should == page1
55
+ Manuscript::Page.find_by_path("#{page1.name}/#{page2.name}").should == page2
56
+ Manuscript::Page.find_by_path("#{page1.name}/#{page2.name}/#{page3.name}").should == page3
57
+ end
58
+
11
59
  it "should restrict names to uri-friendly strings" do
12
60
  should allow_value('page-name').for(:name)
13
61
  should allow_value('page1name').for(:name)
@@ -21,18 +69,17 @@ describe Manuscript::Page do
21
69
  @page = Manuscript::Page.create!(:name => 'words', :contents => 'we **got** em')
22
70
  end
23
71
 
24
- describe "when the page has no template" do
72
+ context "when the page has no template" do
25
73
  it "should render its contents as html directly" do
26
74
  @page.to_html.should == RDiscount.new(@page.contents).to_html
27
75
  end
28
76
  end
29
77
 
30
- describe "when the page has a template" do
78
+ context "when the page has a template" do
31
79
  it "should render its content inside the appropriate template" do
32
80
  @page.template = Manuscript::Template.new(:name =>"Test template", :code => "<h1>Hello templaters!</h1> {{ contents }}" )
33
81
  @page.to_html.should == Liquid::Template.parse(@page.template.code).render({'contents' => RDiscount.new(@page.contents).to_html})
34
82
  end
35
83
  end
36
84
  end
37
-
38
85
  end
data/spec/spec_helper.rb CHANGED
@@ -1,15 +1,14 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
 
4
- require 'active_record'
5
- ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => 'manuscript_test.sqlite3.db'
6
-
7
4
  require 'manuscript'
8
5
  require 'spec'
9
6
  require 'spec/autorun'
10
7
  require 'rack/test'
11
8
  require 'shoulda/active_record'
12
9
 
10
+ ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => 'manuscript_test.sqlite3.db'
11
+
13
12
  require 'database_cleaner'
14
13
  DatabaseCleaner.strategy = :truncation
15
14
 
data/views/_page.haml ADDED
@@ -0,0 +1,10 @@
1
+ %li
2
+ %a{:href => "/admin/pages/#{page.id}/edit"}
3
+ ="/#{page.name}"
4
+ %small
5
+ %a{:style => "color: red;", :onclick => "if(confirm('You are about to delete one of your pages. Click OK to delete or Cancel to return to the page.')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); { f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); } } return false;", :href => "/admin/pages/#{page.id}" } x
6
+ %small
7
+ %a{:href => "/admin/pages/new?parent_id=#{page.id}"} (add subpage)
8
+ %ol.child_pages
9
+ - page.child_pages.each do |child|
10
+ = haml :_page, :locals => { :page => child }, :layout => false
data/views/page.haml CHANGED
@@ -7,7 +7,7 @@
7
7
  %legend Edit page
8
8
  %input{ :type => :submit }
9
9
  %label
10
- Name
10
+ = "Page url:&nbsp;&nbsp;<strong>#{@page.parent_url}/</strong>"
11
11
  %input{:type => :text, :name => "page[name]", :value => "#{@page.name}"}
12
12
  %label
13
13
  Template
@@ -20,6 +20,8 @@
20
20
  - else
21
21
  %option{:value => "#{template.id}"}
22
22
  = template.name
23
+ - unless @page.parent_id.nil?
24
+ %input{:type => :hidden, :name => "page[parent_id]", :value => "#{@page.parent_id}"}
23
25
  %label{:for => "page_contents" }
24
26
  Contents
25
27
  %textarea{:name => "page[contents]", :id => "page_contents"}= @page.contents
data/views/pages.haml CHANGED
@@ -1,8 +1,6 @@
1
1
  %h1 Pages
2
2
  %ol#pages
3
3
  - @pages.each do |page|
4
- %li
5
- %a{:href => "/admin/pages/#{page.id}/edit"}
6
- = "/#{page.name}"
4
+ = haml :_page, :locals => { :page => page }, :layout => false
7
5
 
8
6
  %a.button_link{ :href => "/admin/pages/new" } New page
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manuscript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hotink
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-21 00:00:00 -05:00
12
+ date: 2010-01-22 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -114,6 +114,7 @@ files:
114
114
  - db/migrate/003_add_template_id_to_pages.rb
115
115
  - db/migrate/004_add_layouts_to_templates.rb
116
116
  - db/migrate/005_create_template_files.rb
117
+ - db/migrate/006_add_parent_to_pages.rb
117
118
  - lib/manuscript.rb
118
119
  - lib/manuscript/base.rb
119
120
  - lib/manuscript/keymaster.rb
@@ -139,6 +140,7 @@ files:
139
140
  - spec/manuscript/user_spec.rb
140
141
  - spec/spec.opts
141
142
  - spec/spec_helper.rb
143
+ - views/_page.haml
142
144
  - views/edit_template_file.haml
143
145
  - views/layout.haml
144
146
  - views/menu.haml