tiny_cms 0.2.6 → 0.2.8

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/.gitignore CHANGED
@@ -2,4 +2,6 @@
2
2
  test/rails_app/db/*.sqlite3
3
3
  *.gemspec
4
4
  *.gem
5
- test/rails_app/log/
5
+ test/rails_app/log/
6
+ *.swp
7
+ *.swo
data/Rakefile CHANGED
@@ -9,7 +9,10 @@ begin
9
9
  gem.description = %Q{Minimal CMS Rails Engine or more likelly a "static" pages manager.\nPages can be created, deleted, edited and arranged into sections using a file tree like interface courtesy of jQuery tree (http://jstree.com).\n\nIt attempts to be as minimal, flexible and unobtrusive as posible leaving a lot of functionality like templating languages\nand authentication/authorization for page creation, deletion and editing for the Rails app developer to implement. (It now works after premature release)}
10
10
  gem.email = "macarui@gmail.com"
11
11
  gem.homepage = "http://github.com/maca/tiny_cms"
12
+ gem.post_install_message = %{ \n***********************************\nIf you are updating from previous versions please add new dynamic_route
13
+ and dynamic_route_uuid string fields to your node model.\n***********************************\n\n }
12
14
  gem.authors = ["Macario"]
15
+ gem.add_dependency "uuid", ">= 2.3.1"
13
16
  gem.add_development_dependency "shoulda", ">= 2.11.1"
14
17
  gem.add_development_dependency "rails", ">= 2.3.5"
15
18
  gem.add_development_dependency "factory_girl", ">= 1.3.1"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.2.8
@@ -5,6 +5,11 @@
5
5
  Path: <%= resource.path %>
6
6
  </p>
7
7
 
8
+ <p>
9
+ <%= f.label :dynamic_route %>
10
+ <%= f.text_field :dynamic_route %>
11
+ </p>
12
+
8
13
  <p>
9
14
  <%= f.label :title %>
10
15
  <%= f.text_field :title %>
@@ -23,4 +28,4 @@
23
28
  <p>
24
29
  <%= f.submit %>
25
30
  </p>
26
- <% end %>
31
+ <% end %>
@@ -6,6 +6,7 @@ class TinyCmsCreate<%= table_name.camelize %> < ActiveRecord::Migration
6
6
  t.integer :position
7
7
  t.string :title
8
8
  t.string :content
9
+ t.string :route_to
9
10
 
10
11
  t.timestamps
11
12
  end
@@ -14,4 +15,4 @@ class TinyCmsCreate<%= table_name.camelize %> < ActiveRecord::Migration
14
15
  def self.down
15
16
  drop_table :<%= table_name %>
16
17
  end
17
- end
18
+ end
data/lib/tiny_cms.rb CHANGED
@@ -1,5 +1,7 @@
1
+ require 'uuid'
2
+
1
3
  require 'tiny_cms/node'
2
4
  require 'tiny_cms/pages_controller'
3
5
 
4
6
  module TinyCMS
5
- end
7
+ end
data/lib/tiny_cms/node.rb CHANGED
@@ -53,8 +53,17 @@ module TinyCMS
53
53
  self.children_without_position = array
54
54
  end
55
55
  model.alias_method_chain :children=, :position
56
+
57
+ if model.columns.find { |c| c.name == 'dynamic_route' }
58
+ # dynamic routing
59
+ model.before_save :update_dynamic_route!
60
+ model.after_destroy :remove_dynamic_route!
61
+ model.find(:all, "dynamic_route IS NOT nil").each(&:update_dynamic_route!)
62
+ end
56
63
  end
57
-
64
+
65
+ @@uuid = UUID.new
66
+
58
67
  def parameterize_permalink
59
68
  text = permalink.blank? ? title : permalink
60
69
  self.permalink = text.parameterize if text
@@ -79,5 +88,22 @@ module TinyCMS
79
88
  def to_json opts = {}
80
89
  self.to_hash.to_json
81
90
  end
91
+
92
+ # Dynamic routing
93
+ def add_dynamic_route!
94
+ controller, action = dynamic_route.split('#')
95
+ self.dynamic_route_uuid = @@uuid.generate
96
+ new_route = ActionController::Routing::Routes.builder.build(permalink, {:controller => controller, :action => action, :dynamic_route_uuid => dynamic_route_uuid})
97
+ ActionController::Routing::Routes.routes.unshift new_route
98
+ end
99
+
100
+ def remove_dynamic_route!
101
+ ActionController::Routing::Routes.routes.reject! { |r| r.instance_variable_get(:@requirements)[:dynamic_route_uuid] == dynamic_route_uuid } unless dynamic_route_uuid.blank?
102
+ end
103
+
104
+ def update_dynamic_route!
105
+ remove_dynamic_route!
106
+ add_dynamic_route! unless dynamic_route.blank?
107
+ end
82
108
  end
83
- end
109
+ end
@@ -5,10 +5,10 @@ module TinyCMS
5
5
 
6
6
  def index
7
7
  respond_to do |format|
8
- format.html {
8
+ format.html do
9
9
  @class = klass
10
10
  render 'tiny_cms/index'
11
- }
11
+ end
12
12
  format.json { render :json => klass.include_tree(5).roots }
13
13
  end
14
14
  end
@@ -9,4 +9,3 @@ en:
9
9
  alerts:
10
10
  confirm: Are you sure?
11
11
  duplicate_path: This action would cause two nodes to have the same path (they have the same permalink).
12
-
data/test/helper.rb CHANGED
@@ -11,6 +11,17 @@ require 'shoulda'
11
11
  require 'factory_girl'
12
12
  require 'support/page_migration'
13
13
 
14
+ class Test::Unit::TestCase
15
+ # Hack to be able to do route testing
16
+ def clean_backtrace(&block)
17
+ yield
18
+ rescue ActiveSupport::TestCase::Assertion => error
19
+ framework_path = Regexp.new(File.expand_path("#{File.dirname(__FILE__)}/assertions"))
20
+ error.backtrace.reject! { |line| File.expand_path(line) =~ framework_path }
21
+ raise
22
+ end
23
+ end
24
+
14
25
  Factory.define :page do |p|
15
26
  p.sequence(:title) { |i| "Node #{i}"}
16
27
  p.sequence(:permalink) { |i| "node_#{i}"}
@@ -0,0 +1,5 @@
1
+ class DummyController < ApplicationController
2
+ def index
3
+ end
4
+
5
+ end
@@ -0,0 +1,2 @@
1
+ module DummyHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ <h1>Dummy#index</h1>
2
+ <p>Find me in app/views/dummy/index.html.erb</p>
@@ -1,7 +1,7 @@
1
1
  # Be sure to restart your server when you modify this file
2
2
 
3
3
  # Specifies gem version of Rails to use when vendor/rails is not present
4
- RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
4
+ RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION
5
5
 
6
6
  # Bootstrap the Rails environment, frameworks, and default configuration
7
7
  require File.join(File.dirname(__FILE__), 'boot')
@@ -38,4 +38,4 @@ Rails::Initializer.run do |config|
38
38
  # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
39
39
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
40
40
  # config.i18n.default_locale = :de
41
- end
41
+ end
@@ -9,4 +9,3 @@ en:
9
9
  alerts:
10
10
  confirm: Are you sure?
11
11
  duplicate_path: This action would cause two nodes to have the same path (they have the same permalink).
12
-
@@ -11,7 +11,8 @@ ActiveRecord::Schema.define(:version => 1) do
11
11
  t.integer :position
12
12
  t.string :title
13
13
  t.string :content
14
-
14
+ t.string :dynamic_route
15
+ t.string :dynamic_route_uuid
15
16
  t.timestamps
16
17
  end
17
- end
18
+ end
data/test/test_node.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'helper'
2
2
 
3
3
  class PageTest < Test::Unit::TestCase
4
+ include ActionController::Assertions::RoutingAssertions
5
+
4
6
  should_belong_to :parent
5
7
  should_have_many :children
6
8
 
@@ -262,4 +264,33 @@ class PageTest < Test::Unit::TestCase
262
264
  end
263
265
  end
264
266
  end
267
+
268
+ context 'Dynamic routing' do
269
+ setup do
270
+ @page = Factory :page, :dynamic_route => "dummy#index"
271
+ end
272
+
273
+ should 'generate route' do
274
+ assert_routing @page.path, :controller => 'dummy', :action => 'index', :dynamic_route_uuid => @page.dynamic_route_uuid
275
+ end
276
+
277
+ should 'remove route on destroy' do
278
+ @page.destroy
279
+ assert_equal 0, ActionController::Routing::Routes.routes.select{ |route| route.segments.inject(""){|str,s| str << s.to_s} == "#{@page.path}/" }.size
280
+ end
281
+
282
+ context 'changing route' do
283
+ setup do
284
+ @page.update_attributes :dynamic_route => "dummy#other"
285
+ end
286
+
287
+ should 'generate route' do
288
+ assert_routing @page.path, :controller => 'dummy', :action => 'other', :dynamic_route_uuid => @page.dynamic_route_uuid
289
+ end
290
+
291
+ should 'should remove previous route' do
292
+ assert_equal 1, ActionController::Routing::Routes.routes.select{ |route| route.segments.inject(""){|str,s| str << s.to_s} == "#{@page.path}/" }.size
293
+ end
294
+ end
295
+ end
265
296
  end
@@ -8,6 +8,10 @@ class PagesControllerTest < ActionController::TestCase
8
8
  should_route :get, '/pages/1/edit', :controller => :pages, :action => :edit, :id => '1'
9
9
  should_route :get, '/pages/1', :controller => :pages, :action => :show, :id => '1'
10
10
  should_route :get, '/root/children/children', :controller => :pages, :action => :show, :path => %w(root children children)
11
+
12
+ setup do
13
+ Page.destroy_all
14
+ end
11
15
 
12
16
  context 'get index' do
13
17
  context "as html" do
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_cms
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 7
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
- - 6
9
- version: 0.2.6
9
+ - 8
10
+ version: 0.2.8
10
11
  platform: ruby
11
12
  authors:
12
13
  - Macario
@@ -14,51 +15,73 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-09-08 00:00:00 -05:00
18
+ date: 2010-10-27 00:00:00 -05:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
- name: shoulda
22
+ name: uuid
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 1
30
+ segments:
31
+ - 2
32
+ - 3
33
+ - 1
34
+ version: 2.3.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: shoulda
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
24
42
  requirements:
25
43
  - - ">="
26
44
  - !ruby/object:Gem::Version
45
+ hash: 33
27
46
  segments:
28
47
  - 2
29
48
  - 11
30
49
  - 1
31
50
  version: 2.11.1
32
51
  type: :development
33
- version_requirements: *id001
52
+ version_requirements: *id002
34
53
  - !ruby/object:Gem::Dependency
35
54
  name: rails
36
55
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
38
58
  requirements:
39
59
  - - ">="
40
60
  - !ruby/object:Gem::Version
61
+ hash: 9
41
62
  segments:
42
63
  - 2
43
64
  - 3
44
65
  - 5
45
66
  version: 2.3.5
46
67
  type: :development
47
- version_requirements: *id002
68
+ version_requirements: *id003
48
69
  - !ruby/object:Gem::Dependency
49
70
  name: factory_girl
50
71
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
52
74
  requirements:
53
75
  - - ">="
54
76
  - !ruby/object:Gem::Version
77
+ hash: 25
55
78
  segments:
56
79
  - 1
57
80
  - 3
58
81
  - 1
59
82
  version: 1.3.1
60
83
  type: :development
61
- version_requirements: *id003
84
+ version_requirements: *id004
62
85
  description: |-
63
86
  Minimal CMS Rails Engine or more likelly a "static" pages manager.
64
87
  Pages can be created, deleted, edited and arranged into sections using a file tree like interface courtesy of jQuery tree (http://jstree.com).
@@ -144,9 +167,12 @@ files:
144
167
  - test/rails_app/README
145
168
  - test/rails_app/Rakefile
146
169
  - test/rails_app/app/controllers/application_controller.rb
170
+ - test/rails_app/app/controllers/dummy_controller.rb
147
171
  - test/rails_app/app/controllers/pages_controller.rb
148
172
  - test/rails_app/app/helpers/application_helper.rb
173
+ - test/rails_app/app/helpers/dummy_helper.rb
149
174
  - test/rails_app/app/models/page.rb
175
+ - test/rails_app/app/views/dummy/index.html.erb
150
176
  - test/rails_app/app/views/layouts/application.html.erb
151
177
  - test/rails_app/config/boot.rb
152
178
  - test/rails_app/config/database.yml
@@ -162,8 +188,6 @@ files:
162
188
  - test/rails_app/config/locales/en.yml
163
189
  - test/rails_app/config/locales/tiny_cms.en.yml
164
190
  - test/rails_app/config/routes.rb
165
- - test/rails_app/db/migrate/20100426222349_create_pages.rb
166
- - test/rails_app/db/schema.rb
167
191
  - test/rails_app/db/seeds.rb
168
192
  - test/rails_app/doc/README_FOR_APP
169
193
  - test/rails_app/public/404.html
@@ -183,68 +207,67 @@ files:
183
207
  - test/rails_app/script/plugin
184
208
  - test/rails_app/script/runner
185
209
  - test/rails_app/script/server
186
- - test/rails_app/test/fixtures/pages.yml
187
- - test/rails_app/test/performance/browsing_test.rb
188
- - test/rails_app/test/test_helper.rb
189
- - test/rails_app/test/unit/page_test.rb
190
210
  - test/rails_app/tmp/restart.txt
191
211
  - test/support/page_migration.rb
192
- - test/support/test.sqlite3s
193
212
  - test/test_node.rb
194
213
  - test/test_pages_controller.rb
195
214
  has_rdoc: true
196
215
  homepage: http://github.com/maca/tiny_cms
197
216
  licenses: []
198
217
 
199
- post_install_message:
218
+ post_install_message: " \n\
219
+ ***********************************\n\
220
+ If you are updating from previous versions please add new dynamic_route\n and dynamic_route_uuid string fields to your node model.\n\
221
+ ***********************************\n\n "
200
222
  rdoc_options:
201
223
  - --charset=UTF-8
202
224
  require_paths:
203
225
  - lib
204
226
  required_ruby_version: !ruby/object:Gem::Requirement
227
+ none: false
205
228
  requirements:
206
229
  - - ">="
207
230
  - !ruby/object:Gem::Version
231
+ hash: 3
208
232
  segments:
209
233
  - 0
210
234
  version: "0"
211
235
  required_rubygems_version: !ruby/object:Gem::Requirement
236
+ none: false
212
237
  requirements:
213
238
  - - ">="
214
239
  - !ruby/object:Gem::Version
240
+ hash: 3
215
241
  segments:
216
242
  - 0
217
243
  version: "0"
218
244
  requirements: []
219
245
 
220
246
  rubyforge_project:
221
- rubygems_version: 1.3.6
247
+ rubygems_version: 1.3.7
222
248
  signing_key:
223
249
  specification_version: 3
224
250
  summary: Minimal CMS Rails Engine or more likelly a "static" pages manager
225
251
  test_files:
226
252
  - test/helper.rb
227
- - test/rails_app/app/controllers/application_controller.rb
228
- - test/rails_app/app/controllers/pages_controller.rb
229
- - test/rails_app/app/helpers/application_helper.rb
230
- - test/rails_app/app/models/page.rb
231
- - test/rails_app/config/boot.rb
253
+ - test/rails_app/db/seeds.rb
232
254
  - test/rails_app/config/environment.rb
255
+ - test/rails_app/config/boot.rb
256
+ - test/rails_app/config/routes.rb
257
+ - test/rails_app/config/initializers/backtrace_silencers.rb
258
+ - test/rails_app/config/initializers/session_store.rb
259
+ - test/rails_app/config/initializers/new_rails_defaults.rb
260
+ - test/rails_app/config/initializers/mime_types.rb
261
+ - test/rails_app/config/initializers/inflections.rb
233
262
  - test/rails_app/config/environments/development.rb
234
263
  - test/rails_app/config/environments/production.rb
235
264
  - test/rails_app/config/environments/test.rb
236
- - test/rails_app/config/initializers/backtrace_silencers.rb
237
- - test/rails_app/config/initializers/inflections.rb
238
- - test/rails_app/config/initializers/mime_types.rb
239
- - test/rails_app/config/initializers/new_rails_defaults.rb
240
- - test/rails_app/config/initializers/session_store.rb
241
- - test/rails_app/config/routes.rb
242
- - test/rails_app/db/migrate/20100426222349_create_pages.rb
243
- - test/rails_app/db/schema.rb
244
- - test/rails_app/db/seeds.rb
245
- - test/rails_app/test/performance/browsing_test.rb
246
- - test/rails_app/test/test_helper.rb
247
- - test/rails_app/test/unit/page_test.rb
248
- - test/support/page_migration.rb
265
+ - test/rails_app/app/models/page.rb
266
+ - test/rails_app/app/helpers/dummy_helper.rb
267
+ - test/rails_app/app/helpers/application_helper.rb
268
+ - test/rails_app/app/controllers/dummy_controller.rb
269
+ - test/rails_app/app/controllers/application_controller.rb
270
+ - test/rails_app/app/controllers/pages_controller.rb
249
271
  - test/test_node.rb
250
272
  - test/test_pages_controller.rb
273
+ - test/support/page_migration.rb
@@ -1,19 +0,0 @@
1
- class CreatePages < ActiveRecord::Migration
2
- def self.up
3
- create_table :pages do |t|
4
- t.integer :parent_id
5
- t.string :permalink
6
- t.string :path
7
- t.integer :position
8
- t.string :title
9
- t.string :content
10
- t.boolean :is_page
11
-
12
- t.timestamps
13
- end
14
- end
15
-
16
- def self.down
17
- drop_table :pages
18
- end
19
- end
@@ -1,26 +0,0 @@
1
- # This file is auto-generated from the current state of the database. Instead of editing this file,
2
- # please use the migrations feature of Active Record to incrementally modify your database, and
3
- # then regenerate this schema definition.
4
- #
5
- # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6
- # to create the application database on another system, you should be using db:schema:load, not running
7
- # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8
- # you'll amass, the slower it'll run and the greater likelihood for issues).
9
- #
10
- # It's strongly recommended to check this file into your version control system.
11
-
12
- ActiveRecord::Schema.define(:version => 20100426222349) do
13
-
14
- create_table "pages", :force => true do |t|
15
- t.integer "parent_id"
16
- t.string "permalink"
17
- t.string "path"
18
- t.integer "position"
19
- t.string "title"
20
- t.string "content"
21
- t.boolean "is_page"
22
- t.datetime "created_at"
23
- t.datetime "updated_at"
24
- end
25
-
26
- end
@@ -1,17 +0,0 @@
1
- # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
-
3
- one:
4
- parent_id: 1
5
- permalink: MyString
6
- path: MyString
7
- position: 1
8
- title: MyString
9
- content: MyString
10
-
11
- two:
12
- parent_id: 1
13
- permalink: MyString
14
- path: MyString
15
- position: 1
16
- title: MyString
17
- content: MyString
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
- require 'performance_test_help'
3
-
4
- # Profiling results for each test method are written to tmp/performance.
5
- class BrowsingTest < ActionController::PerformanceTest
6
- def test_homepage
7
- get '/'
8
- end
9
- end
@@ -1,38 +0,0 @@
1
- ENV["RAILS_ENV"] = "test"
2
- require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
- require 'test_help'
4
-
5
- class ActiveSupport::TestCase
6
- # Transactional fixtures accelerate your tests by wrapping each test method
7
- # in a transaction that's rolled back on completion. This ensures that the
8
- # test database remains unchanged so your fixtures don't have to be reloaded
9
- # between every test method. Fewer database queries means faster tests.
10
- #
11
- # Read Mike Clark's excellent walkthrough at
12
- # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
13
- #
14
- # Every Active Record database supports transactions except MyISAM tables
15
- # in MySQL. Turn off transactional fixtures in this case; however, if you
16
- # don't care one way or the other, switching from MyISAM to InnoDB tables
17
- # is recommended.
18
- #
19
- # The only drawback to using transactional fixtures is when you actually
20
- # need to test transactions. Since your test is bracketed by a transaction,
21
- # any transactions started in your code will be automatically rolled back.
22
- self.use_transactional_fixtures = true
23
-
24
- # Instantiated fixtures are slow, but give you @david where otherwise you
25
- # would need people(:david). If you don't want to migrate your existing
26
- # test cases which use the @david style and don't mind the speed hit (each
27
- # instantiated fixtures translates to a database query per test method),
28
- # then set this back to true.
29
- self.use_instantiated_fixtures = false
30
-
31
- # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
32
- #
33
- # Note: You'll currently still have to declare fixtures explicitly in integration tests
34
- # -- they do not yet inherit this setting
35
- fixtures :all
36
-
37
- # Add more helper methods to be used by all tests here...
38
- end
@@ -1,8 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PageTest < ActiveSupport::TestCase
4
- # Replace this with your real tests.
5
- test "the truth" do
6
- assert true
7
- end
8
- end
Binary file