eric 0.0.1

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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Eric
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Eric'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,5 @@
1
+ class PagesController < ApplicationController
2
+ def show
3
+ @page = Page.find_by_path(params[:path])
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class PostsController < ApplicationController
2
+ def index
3
+ @posts = Post.all
4
+ end
5
+
6
+ def show
7
+ @post = Post.find(params[:id])
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module BlocksHelper
2
+ def render_block(name)
3
+ block = Block.find_by_name(name)
4
+
5
+ if block
6
+ render block
7
+ else
8
+ "render_block: Block not found \"#{name}\"" if Rails.env.development?
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class Block < ActiveRecord::Base
2
+ attr_accessible :name, :title, :body, as: [:default, :admin]
3
+
4
+ validates :name, presence: true, uniqueness: true
5
+ end
@@ -0,0 +1,46 @@
1
+ class Page < ActiveRecord::Base
2
+ has_ancestry
3
+ extend FriendlyId
4
+ friendly_id :title, use: [:slugged, :scoped], scope: :ancestry
5
+
6
+ attr_accessible :parent_id, :parent, :body, :order, :slug, :title,
7
+ as: [:default, :admin]
8
+
9
+ validates :title, presence: true
10
+
11
+ def self.find_by_path(path)
12
+ # TODO: this gets called twice for all Page requests. should probably be more efficient.
13
+ ancestors = path.split('/').reject { |s| s.empty? }
14
+ result = Page.roots.find_by_slug(ancestors.shift)
15
+ result = result.children.find_by_slug(ancestors.shift) while ancestors.any? && !!result
16
+ result
17
+ end
18
+
19
+ def self.find_by_path!(path)
20
+ if result = Page.find_by_path(path)
21
+ result
22
+ else
23
+ raise ActiveRecord::RecordNotFound, "Couldn't find Page with path = #{path}"
24
+ end
25
+ end
26
+
27
+ def self.path_exists?(path)
28
+ # TODO: if there's a more efficient way to do this, I should put it here
29
+ Page.find_by_path(path)
30
+ end
31
+
32
+ def url
33
+ url = '/'
34
+ url << ancestors.map { |a| a.slug }.join('/') << '/' if !is_root?
35
+ url << slug
36
+ end
37
+
38
+ def should_generate_new_friendly_id?
39
+ slug.blank?
40
+ end
41
+
42
+ before_save :set_default_order
43
+ def set_default_order
44
+ self.order ||= siblings.any? ? siblings.order('"order" DESC').limit(1).first.order + 1 : 0
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ class Post < ActiveRecord::Base
2
+ attr_accessible :body, :date, :title, as: [:default, :admin]
3
+
4
+ validates :date, presence: true
5
+ validates :title, presence: true
6
+ validates :body, presence: true
7
+
8
+ default_scope order("date DESC")
9
+ end
@@ -0,0 +1,8 @@
1
+ <%= div_for block do %>
2
+ <% if block.title.present? %>
3
+ <h3><%= block.title %></h3>
4
+ <% end %>
5
+ <% if block.body.present? %>
6
+ <%= simple_format block.body %>
7
+ <% end %>
8
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <ul>
2
+ <% pages.each do |page, children| %>
3
+ <li>
4
+ <%= link_to_unless_current page.title, page.url %>
5
+ <%= render 'submenu_pages', pages: children if children.present? %>
6
+ </li>
7
+ <% end %>
8
+ </ul>
@@ -0,0 +1,12 @@
1
+ <%
2
+ # For advanced styling tips like breadcrumbs and a top-level nav
3
+ # see http://railscasts.com/episodes/162-tree-based-navigation-revised
4
+ %>
5
+
6
+ <% content_for :title, @page.title %>
7
+
8
+ <%= render 'submenu_pages', pages: @page.root.subtree.arrange(order: '"order"') %>
9
+
10
+ <h1><%= @page.title %></h1>
11
+
12
+ <%= raw @page.body %>
@@ -0,0 +1,8 @@
1
+ <%= div_for post do %>
2
+ <h3>
3
+ <%= post.title %>
4
+ </h3>
5
+ <h4><%= post.date.strftime('%m/%d/%y') %></h4>
6
+
7
+ <%= simple_format post.body %>
8
+ <% end %>
@@ -0,0 +1,2 @@
1
+ <h2>Blog</h2>
2
+ <%= render @posts %>
@@ -0,0 +1 @@
1
+ <%= render @post %>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ resources :posts, only: [:index, :show]
3
+
4
+ match '*path' => 'pages#show', constraints: ->(request) { Page.path_exists?(request.path) }
5
+ end
@@ -0,0 +1,13 @@
1
+ class CreateBlocks < ActiveRecord::Migration
2
+ def change
3
+ create_table :blocks do |t|
4
+ t.string :name, null: false
5
+ t.string :title, null: false, default: ''
6
+ t.text :body, null: false, default: ''
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :blocks, :name, unique: true
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+ t.date :date, null: false
5
+ t.string :title, null: false, default: ''
6
+ t.text :body, null: false, default: ''
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :posts, :date
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ class CreatePages < ActiveRecord::Migration
2
+ def change
3
+ create_table :pages do |t|
4
+ t.string :slug, null: false
5
+ t.string :title, null: false, default: ''
6
+ t.text :body, null: false, default: ''
7
+ t.string :ancestry
8
+ t.integer :order, null: false
9
+
10
+ t.timestamps
11
+ end
12
+ add_index :pages, :slug
13
+ add_index :pages, :ancestry
14
+ add_index :pages, :order
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ module Eric
2
+ class Engine < ::Rails::Engine
3
+ config.generators.integration_tool :rspec
4
+ config.generators.test_framework :rspec
5
+
6
+ engine_name "eric"
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Eric
2
+ VERSION = "0.0.1"
3
+ end
data/lib/eric.rb ADDED
@@ -0,0 +1,9 @@
1
+ # Dependencies
2
+ require "ancestry"
3
+ require "friendly_id"
4
+
5
+ # Eric
6
+ require "eric/engine"
7
+
8
+ module Eric
9
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :eric do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,251 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eric
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Taavo Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.9
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.9
30
+ - !ruby/object:Gem::Dependency
31
+ name: ancestry
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: friendly_id
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sqlite3
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec-rails
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: capybara
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: shoulda-matchers
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: factory_girl_rails
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: guard-rspec
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: guard-spork
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: rb-fsevent
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ~>
180
+ - !ruby/object:Gem::Version
181
+ version: 0.9.1
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ~>
188
+ - !ruby/object:Gem::Version
189
+ version: 0.9.1
190
+ description: A CMS for sites which already have a back-end and don't want another.
191
+ Pages, posts, and blocks.
192
+ email:
193
+ - taavo@dd9.com
194
+ executables: []
195
+ extensions: []
196
+ extra_rdoc_files: []
197
+ files:
198
+ - app/controllers/pages_controller.rb
199
+ - app/controllers/posts_controller.rb
200
+ - app/helpers/blocks_helper.rb
201
+ - app/models/block.rb
202
+ - app/models/page.rb
203
+ - app/models/post.rb
204
+ - app/views/blocks/_block.html.erb
205
+ - app/views/pages/_submenu_pages.html.erb
206
+ - app/views/pages/show.html.erb
207
+ - app/views/posts/_post.html.erb
208
+ - app/views/posts/index.html.erb
209
+ - app/views/posts/show.html.erb
210
+ - config/routes.rb
211
+ - db/migrate/20121205161832_create_blocks.rb
212
+ - db/migrate/20121205165447_create_posts.rb
213
+ - db/migrate/20121206140606_create_pages.rb
214
+ - lib/eric/engine.rb
215
+ - lib/eric/version.rb
216
+ - lib/eric.rb
217
+ - lib/tasks/eric_tasks.rake
218
+ - MIT-LICENSE
219
+ - Rakefile
220
+ - README.rdoc
221
+ homepage: http://github.com/dd9/eric
222
+ licenses: []
223
+ post_install_message:
224
+ rdoc_options: []
225
+ require_paths:
226
+ - lib
227
+ required_ruby_version: !ruby/object:Gem::Requirement
228
+ none: false
229
+ requirements:
230
+ - - ! '>='
231
+ - !ruby/object:Gem::Version
232
+ version: '0'
233
+ segments:
234
+ - 0
235
+ hash: 1002657868316071926
236
+ required_rubygems_version: !ruby/object:Gem::Requirement
237
+ none: false
238
+ requirements:
239
+ - - ! '>='
240
+ - !ruby/object:Gem::Version
241
+ version: '0'
242
+ segments:
243
+ - 0
244
+ hash: 1002657868316071926
245
+ requirements: []
246
+ rubyforge_project:
247
+ rubygems_version: 1.8.23
248
+ signing_key:
249
+ specification_version: 3
250
+ summary: Half of a CMS. The front half.
251
+ test_files: []