amiba 0.0.9 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,12 +40,46 @@ module Protozoa
40
40
  enable :logging, :raise_errors, :dump_errors
41
41
  end
42
42
 
43
+ helpers do
44
+ def all_pages
45
+ Dir.glob('pages/**/[^_]*').inject([]) do |acc, page_file|
46
+ if !File.directory? page_file
47
+ page = Amiba::Source::Page.new(File.relpath(page_file, "pages"))
48
+ ent = Amiba::Source::PageEntry.new(page)
49
+ acc << page unless ent.new?
50
+ end
51
+ acc
52
+ end
53
+ end
54
+ end
55
+
43
56
  get '/' do
57
+ pull
44
58
  @entries = Amiba::Source::Entry.any.all.sort {|a,b| a.category <=> b.category }
59
+ @pages = all_pages
45
60
  mustache :index
46
61
  end
47
62
 
63
+ get %r{/pages/edit/(.+)\.html$} do
64
+ pull
65
+ @page = Amiba::Source::Page.new(params[:captures][0],"haml")
66
+ @entry = Amiba::Source::PageEntry.new(@page)
67
+ @content = @entry.content
68
+ @name = @page.title
69
+ mustache :edit
70
+ end
71
+
72
+ get %r{/pages/(.+)\.html$} do
73
+ @page = Amiba::Source::Page.new(params[:captures][0],"haml")
74
+ @entry = Amiba::Source::PageEntry.new(@page)
75
+ @content = @entry.render
76
+ @name = @page.title
77
+ @editable = true
78
+ mustache :page
79
+ end
80
+
48
81
  get %r{/entries/edit/(.+?)/(.+)\.html$} do
82
+ pull
49
83
  @page = Amiba::Source::Entry.new(params[:captures][0],params[:captures][1],"markdown")
50
84
  @content = @page.content
51
85
  @name = @page.title
@@ -60,7 +94,21 @@ module Protozoa
60
94
  mustache :page
61
95
  end
62
96
 
97
+ post %r{/pages/edit/(.+)\.html$} do
98
+ pull
99
+ @page = Amiba::Source::Page.new(params[:captures][0],"haml")
100
+ @entry = Amiba::Source::PageEntry.new(@page)
101
+ @entry.content = params[:content]
102
+ @entry.save do |filename, file_data|
103
+ File.open(filename, 'w') { |f| f.write(file_data) }
104
+ end
105
+ add_and_commit @entry.filename
106
+ push
107
+ redirect "/pages#{@page.link}"
108
+ end
109
+
63
110
  post %r{/entries/edit/(.+?)/(.+)\.html$} do
111
+ pull
64
112
  @page = Amiba::Source::Entry.new(params[:captures][0],params[:captures][1],"markdown")
65
113
  @page.content = params[:content]
66
114
  @page.author = env["X-DSCI-USER"] || "Anonymous"
@@ -68,7 +116,7 @@ module Protozoa
68
116
  File.open(filename, 'w') { |f| f.write(file_data) }
69
117
  end
70
118
  add_and_commit @page.filename
71
- # push
119
+ push
72
120
  redirect "/entries#{@page.link}"
73
121
  end
74
122
 
@@ -88,6 +136,7 @@ module Protozoa
88
136
  end
89
137
 
90
138
  post '/entries/create' do
139
+ pull
91
140
  name = params[:title].parameterize
92
141
  metadata = {state: "published", title: params[:title]}
93
142
  @page = Amiba::Source::Entry.new(params[:category], name, "markdown", metadata, params[:content])
@@ -96,7 +145,7 @@ module Protozoa
96
145
  File.open(filename, 'w') { |f| f.write(file_data) }
97
146
  end
98
147
  add_and_commit @page.filename
99
- # push
148
+ push
100
149
  redirect "/entries#{@page.link}"
101
150
  end
102
151
 
@@ -2,7 +2,7 @@
2
2
  <div id="head">
3
3
  <h1>Editing <strong>{{title}}</strong></h1>
4
4
  <ul class="actions">
5
- <li class="minibutton"><a href="/entries{{page.link}}"
5
+ <li class="minibutton"><a href="{{view_url}}"
6
6
  class="action-view-page">View Page</a></li>
7
7
  <!-- <li class="minibutton"><a href="/history{{page.link}}"
8
8
  class="action-page-history">Page History</a></li> -->
@@ -10,6 +10,7 @@
10
10
  </div>
11
11
  <div id="results">
12
12
 
13
+ <h2> Individual Entries</h2>
13
14
  {{#has_entries}}
14
15
  <ul>
15
16
  {{#entries}}
@@ -20,6 +21,15 @@
20
21
  </ul>
21
22
  {{/has_entries}}
22
23
 
24
+ <h2>Pages</h2>
25
+ <ul>
26
+ {{#pages}}
27
+ <li>
28
+ <a href="/pages{{link}}">{{title}}</a>
29
+ </li>
30
+ {{/pages}}
31
+ </ul>
32
+
23
33
  {{#no_entries}}
24
34
  <p id="no-entries">
25
35
  There are no pages in <strong>{{ref}}</strong>.
@@ -1,7 +1,7 @@
1
1
  module Protozoa
2
2
  module Views
3
3
  class Index < Layout
4
- attr_reader :entries, :ref
4
+ attr_reader :entries, :ref, :pages
5
5
 
6
6
  def title
7
7
  "All pages for #{Amiba::Configuration.site_name}"
@@ -16,6 +16,14 @@ module Protozoa
16
16
  "Home"
17
17
  end
18
18
 
19
+ def view_url
20
+ if @page.class == Amiba::Source::Entry
21
+ "/entries#{@page.link}"
22
+ else
23
+ "/pages#{@page.link}"
24
+ end
25
+ end
26
+
19
27
  def edit_url
20
28
  if @page.class == Amiba::Source::Entry
21
29
  "/entries/edit#{@page.link}"
data/lib/amiba/repo.rb CHANGED
@@ -29,5 +29,9 @@ module Amiba
29
29
  def push(remote=nil,branch=nil,args={})
30
30
  repo.git.push(args,remote,branch)
31
31
  end
32
+
33
+ def pull
34
+ repo.git.pull
35
+ end
32
36
  end
33
37
  end
@@ -65,6 +65,10 @@ module Amiba
65
65
  File.join("entries", name + ".#{format.to_s}")
66
66
  end
67
67
 
68
+ def render
69
+ Amiba::Tilt.new(self).render(Amiba::Scope.new(self))
70
+ end
71
+
68
72
  alias_method :output_filename, :filename
69
73
  end
70
74
 
data/lib/amiba/source.rb CHANGED
@@ -124,6 +124,10 @@ module Amiba
124
124
  VALID_FORMATS = %w{haml markdown}
125
125
  validates_presence_of :layout, :title, :description, :category, :state
126
126
 
127
+ def link
128
+ URI.escape( ["", "#{name}.html"].join("/") )
129
+ end
130
+
127
131
  def output_filename
128
132
  File.join(Amiba::Configuration.site_dir, "public/#{name}.html")
129
133
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amiba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-08-16 00:00:00.000000000Z
13
+ date: 2011-08-17 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor
17
- requirement: &70105019667120 !ruby/object:Gem::Requirement
17
+ requirement: &70152402485620 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.14.6
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70105019667120
25
+ version_requirements: *70152402485620
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: tilt
28
- requirement: &70105019666660 !ruby/object:Gem::Requirement
28
+ requirement: &70152402485020 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.3.2
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70105019666660
36
+ version_requirements: *70152402485020
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: haml
39
- requirement: &70105019666120 !ruby/object:Gem::Requirement
39
+ requirement: &70152402484280 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 3.0.25
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70105019666120
47
+ version_requirements: *70152402484280
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: activemodel
50
- requirement: &70105019665640 !ruby/object:Gem::Requirement
50
+ requirement: &70152402483660 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 3.0.4
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70105019665640
58
+ version_requirements: *70152402483660
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: i18n
61
- requirement: &70105019665180 !ruby/object:Gem::Requirement
61
+ requirement: &70152402483080 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 0.5.0
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *70105019665180
69
+ version_requirements: *70152402483080
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: redcarpet
72
- requirement: &70105019664800 !ruby/object:Gem::Requirement
72
+ requirement: &70152402482660 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :runtime
79
79
  prerelease: false
80
- version_requirements: *70105019664800
80
+ version_requirements: *70152402482660
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rdiscount
83
- requirement: &70105019664320 !ruby/object:Gem::Requirement
83
+ requirement: &70152402482080 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :runtime
90
90
  prerelease: false
91
- version_requirements: *70105019664320
91
+ version_requirements: *70152402482080
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: fog
94
- requirement: &70105019663700 !ruby/object:Gem::Requirement
94
+ requirement: &70152402481500 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: 0.7.0
100
100
  type: :runtime
101
101
  prerelease: false
102
- version_requirements: *70105019663700
102
+ version_requirements: *70152402481500
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: grit
105
- requirement: &70105019663200 !ruby/object:Gem::Requirement
105
+ requirement: &70152402480820 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ~>
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: 2.4.1
111
111
  type: :runtime
112
112
  prerelease: false
113
- version_requirements: *70105019663200
113
+ version_requirements: *70152402480820
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: rspec
116
- requirement: &70105019662820 !ruby/object:Gem::Requirement
116
+ requirement: &70152402480360 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: '0'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *70105019662820
124
+ version_requirements: *70152402480360
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec_tag_matchers
127
- requirement: &70105019662360 !ruby/object:Gem::Requirement
127
+ requirement: &70152402479880 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ! '>='
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: '0'
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *70105019662360
135
+ version_requirements: *70152402479880
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: autotest
138
- requirement: &70105019661940 !ruby/object:Gem::Requirement
138
+ requirement: &70152402479280 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ! '>='
@@ -143,10 +143,10 @@ dependencies:
143
143
  version: '0'
144
144
  type: :development
145
145
  prerelease: false
146
- version_requirements: *70105019661940
146
+ version_requirements: *70152402479280
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: factory_girl
149
- requirement: &70105019661380 !ruby/object:Gem::Requirement
149
+ requirement: &70152402478700 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
152
152
  - - ! '>='
@@ -154,7 +154,7 @@ dependencies:
154
154
  version: 2.0.0.beta1
155
155
  type: :development
156
156
  prerelease: false
157
- version_requirements: *70105019661380
157
+ version_requirements: *70152402478700
158
158
  description: Description TBD
159
159
  email:
160
160
  - s.mohapi-banks@digital-science.com