compages 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.project +18 -0
- data/README +180 -0
- data/Rakefile +10 -0
- data/app/controllers/application.rb +4 -0
- data/app/controllers/contents_controller.rb +116 -0
- data/app/controllers/pages_controller.rb +59 -0
- data/app/controllers/render_controller.rb +24 -0
- data/app/helpers/application_helper.rb +6 -0
- data/app/helpers/contents_helper.rb +5 -0
- data/app/helpers/pages_helper.rb +5 -0
- data/app/helpers/render_helper.rb +2 -0
- data/app/models/content.rb +26 -0
- data/app/models/meta_data.rb +3 -0
- data/app/models/page.rb +106 -0
- data/app/models/page_element.rb +9 -0
- data/app/views/contents/_content_preview.rhtml +1 -0
- data/app/views/contents/_contents_list.rhtml +3 -0
- data/app/views/contents/_show_library.rhtml +60 -0
- data/app/views/contents/_write_now.rhtml +42 -0
- data/app/views/layouts/pages.rhtml +24 -0
- data/app/views/layouts/render.rhtml +11 -0
- data/app/views/pages/_change_theme.rhtml +0 -0
- data/app/views/pages/_edit_menu.rhtml +62 -0
- data/app/views/pages/_page_listed.rhtml +13 -0
- data/app/views/pages/_select_theme.rhtml +4 -0
- data/app/views/pages/edit.rhtml +35 -0
- data/app/views/pages/index.rhtml +45 -0
- data/app/views/pages/list.rhtml +41 -0
- data/app/views/pages/list_a.rhtml +40 -0
- data/app/views/pages/welcome.rhtml +27 -0
- data/app/views/render/_blank.rhtml +3 -0
- data/app/views/render/show.rhtml +1 -0
- data/bin/compages +14 -0
- data/config/boot.rb +44 -0
- data/config/database.yml.home +35 -0
- data/config/environment.rb +53 -0
- data/config/environments/development.rb +21 -0
- data/config/environments/production.rb +18 -0
- data/config/environments/test.rb +19 -0
- data/config/routes.rb +32 -0
- data/db/Copia di schema.rb +48 -0
- data/db/migrate/001_create_pages.rb +12 -0
- data/db/migrate/002_create_contents.rb +12 -0
- data/db/migrate/003_create_meta_datas.rb +14 -0
- data/db/migrate/004_create_page_elements.rb +17 -0
- data/db/migrate/005_add_urlnames.rb +15 -0
- data/db/migrate/006_add_sessions.rb +15 -0
- data/db/schema.mysql.sql +65 -0
- data/db/schema.postgresql.sql +65 -0
- data/db/schema.rb +49 -0
- data/db/schema.sqlite.sql +65 -0
- data/db/schema.sqlserver.sql +71 -0
- data/db/schema_version +1 -0
- data/doc/ER-model/v1.dia +0 -0
- data/doc/ER-model/v2.dia +0 -0
- data/doc/ER-model/v3.dia +0 -0
- data/doc/README_FOR_APP +2 -0
- data/doc/esempi/doc-vir/ecds.htm +2362 -0
- data/doc/esempi/doc-vir/ecds_files/search.gif +0 -0
- data/doc/esempi/doc-vir/ecds_files/upld.gif +0 -0
- data/doc/esempi/doc-vir/ecds_files/upld.jpg +0 -0
- data/installer/apache13.conf.example.template +33 -0
- data/installer/apache20.conf.example.template +40 -0
- data/installer/lighttpd.conf.example.template +6 -0
- data/installer/rails_installer_defaults.yml +5 -0
- data/lib/redcloth.rb +1130 -0
- data/lib/render_engine.rb +94 -0
- data/lib/tasks/release.rake +46 -0
- data/public/.htaccess +41 -0
- data/public/404.html +8 -0
- data/public/500.html +8 -0
- data/public/_index.html +277 -0
- data/public/favicon.ico +0 -0
- data/public/images/body_bg.gif +0 -0
- data/public/images/body_bg_short.gif +0 -0
- data/public/images/ie_shadow.png +0 -0
- data/public/images/journal_reflex.gif +0 -0
- data/public/images/journal_shadow.gif +0 -0
- data/public/images/logo_journal_small.bmp +0 -0
- data/public/images/logo_journal_small.png +0 -0
- data/public/images/page_edit_shadow.png +0 -0
- data/public/images/restore_bar.png +0 -0
- data/public/images/spinner.gif +0 -0
- data/public/javascripts/application.js +23 -0
- data/public/javascripts/controls.js +815 -0
- data/public/javascripts/dragdrop.js +913 -0
- data/public/javascripts/effects.js +958 -0
- data/public/javascripts/lowpro.js +307 -0
- data/public/javascripts/prototype.js +2006 -0
- data/public/robots.txt +1 -0
- data/public/stylesheets/compages.css +196 -0
- data/public/stylesheets/editing.css +180 -0
- data/public/stylesheets/editing_ie_filth.css +36 -0
- data/public/themes/Doc_basic/_script.js +342 -0
- data/public/themes/Doc_basic/images/Thumbs.db +0 -0
- data/public/themes/Doc_basic/images/search.gif +0 -0
- data/public/themes/Doc_basic/images/upld.gif +0 -0
- data/public/themes/Doc_basic/images/upld.jpg +0 -0
- data/public/themes/Doc_basic/index.html +114 -0
- data/public/themes/Doc_basic/style.css +1743 -0
- data/public/themes/color7boxes/default2.css +42 -0
- data/public/themes/color7boxes/index.html +40 -0
- data/public/themes/prova/index.html +12 -0
- data/public/zDoc/images/search.gif +0 -0
- data/public/zDoc/images/upld.gif +0 -0
- data/public/zDoc/images/upld.jpg +0 -0
- data/public/zDoc/index.html +176 -0
- data/public/zDoc/script.js +342 -0
- data/public/zDoc/style.css +1741 -0
- data/script/about +3 -0
- data/script/breakpointer +3 -0
- data/script/console +3 -0
- data/script/destroy +3 -0
- data/script/generate +3 -0
- data/script/performance/benchmarker +3 -0
- data/script/performance/profiler +3 -0
- data/script/plugin +3 -0
- data/script/process/reaper +3 -0
- data/script/process/spawner +3 -0
- data/script/runner +3 -0
- data/script/server +3 -0
- data/test/fixtures/contents.yml +5 -0
- data/test/fixtures/meta_datas.yml +5 -0
- data/test/fixtures/page_elements.yml +5 -0
- data/test/fixtures/pages.yml +5 -0
- data/test/functional/contents_controller_test.rb +18 -0
- data/test/functional/pages_controller_test.rb +18 -0
- data/test/functional/render_controller_test.rb +18 -0
- data/test/test_helper.rb +28 -0
- data/test/unit/content_test.rb +10 -0
- data/test/unit/meta_data_test.rb +10 -0
- data/test/unit/page_element_test.rb +10 -0
- data/test/unit/page_test.rb +10 -0
- data/tmp/sessions/ruby_sess.0ced4c30e36477ab +0 -0
- data/tmp/sessions/ruby_sess.20fbe26671422e70 +0 -0
- data/tmp/sessions/ruby_sess.2c72521f3a7e2ba9 +0 -0
- data/tmp/sessions/ruby_sess.4107a69d982a2eb7 +0 -0
- data/tmp/sessions/ruby_sess.573ded9c7fdd9035 +0 -0
- data/tmp/sessions/ruby_sess.5a9767815bb96258 +0 -0
- data/tmp/sessions/ruby_sess.85d723b794005388 +0 -0
- data/tmp/sessions/ruby_sess.875b3b3e3529afdb +0 -0
- data/tmp/sessions/ruby_sess.936766f3a397c88b +0 -0
- data/tmp/sessions/ruby_sess.984e2e4c9a2e7891 +0 -0
- data/tmp/sessions/ruby_sess.a1faebd7448bc45d +0 -0
- data/tmp/sessions/ruby_sess.a415768c7635bc15 +0 -0
- data/tmp/sessions/ruby_sess.b2dadcbe6c1b0add +0 -0
- data/tmp/sessions/ruby_sess.ca9100beb103a428 +0 -0
- data/tmp/sessions/ruby_sess.d649c800a046efde +0 -0
- data/tmp/sessions/ruby_sess.db73bbfafd5a537c +0 -0
- data/tmp/sessions/ruby_sess.e32487b847524df1 +0 -0
- data/tmp/sessions/ruby_sess.f4e45d67828cc437 +0 -0
- data/tmp/sessions/ruby_sess.f5a3f064f2f7a26f +0 -0
- data/tmp/sessions/ruby_sess.ff0c47b35f238cda +0 -0
- data/vendor/plugins/acts_as_urlnameable.tar.gz +0 -0
- data/vendor/plugins/acts_as_urlnameable/LICENSE +19 -0
- data/vendor/plugins/acts_as_urlnameable/README +193 -0
- data/vendor/plugins/acts_as_urlnameable/Rakefile +25 -0
- data/vendor/plugins/acts_as_urlnameable/TODO +5 -0
- data/vendor/plugins/acts_as_urlnameable/db/00x_add_urlnames_table.rb +15 -0
- data/vendor/plugins/acts_as_urlnameable/db/urlnames_table.sql +7 -0
- data/vendor/plugins/acts_as_urlnameable/doc/classes/ActiveRecord/Acts/Urlnameable/ClassMethods.html +167 -0
- data/vendor/plugins/acts_as_urlnameable/doc/classes/ActiveRecord/Acts/Urlnameable/InstanceMethods.html +213 -0
- data/vendor/plugins/acts_as_urlnameable/doc/classes/ActiveRecord/Acts/Urlnameable/SingletonMethods.html +189 -0
- data/vendor/plugins/acts_as_urlnameable/doc/created.rid +1 -0
- data/vendor/plugins/acts_as_urlnameable/doc/files/LICENSE.html +129 -0
- data/vendor/plugins/acts_as_urlnameable/doc/files/README.html +333 -0
- data/vendor/plugins/acts_as_urlnameable/doc/files/TODO.html +121 -0
- data/vendor/plugins/acts_as_urlnameable/doc/files/lib/acts_as_urlnameable_rb.html +101 -0
- data/vendor/plugins/acts_as_urlnameable/doc/fr_class_index.html +29 -0
- data/vendor/plugins/acts_as_urlnameable/doc/fr_file_index.html +30 -0
- data/vendor/plugins/acts_as_urlnameable/doc/fr_method_index.html +34 -0
- data/vendor/plugins/acts_as_urlnameable/doc/index.html +24 -0
- data/vendor/plugins/acts_as_urlnameable/doc/rdoc-style.css +208 -0
- data/vendor/plugins/acts_as_urlnameable/init.rb +3 -0
- data/vendor/plugins/acts_as_urlnameable/lib/acts_as_urlnameable.rb +159 -0
- data/vendor/plugins/acts_as_urlnameable/lib/urlname.rb +3 -0
- data/vendor/plugins/acts_as_urlnameable/test/acts_as_urlnameable_test.rb +233 -0
- data/vendor/plugins/acts_as_urlnameable/test/connection.rb +8 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/article.rb +13 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/articles.yml +62 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/page.rb +14 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/pages.yml +35 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/people.yml +9 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/person.rb +26 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/schema.rb +24 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/section.rb +5 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/sections.yml +9 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/urlnames.yml +153 -0
- data/vendor/plugins/acts_as_urlnameable/test/test_helper.rb +42 -0
- data/vendor/plugins/gems/README +30 -0
- data/vendor/plugins/gems/init.rb +9 -0
- data/vendor/plugins/gems/tasks/gems_tasks.rake +32 -0
- data/vendor/plugins/unobtrusive_javascript/CHANGELOG +72 -0
- data/vendor/plugins/unobtrusive_javascript/README +73 -0
- data/vendor/plugins/unobtrusive_javascript/Rakefile +33 -0
- data/vendor/plugins/unobtrusive_javascript/about.yml +6 -0
- data/vendor/plugins/unobtrusive_javascript/assets/javascripts/lowpro.js +307 -0
- data/vendor/plugins/unobtrusive_javascript/init.rb +21 -0
- data/vendor/plugins/unobtrusive_javascript/install.rb +1 -0
- data/vendor/plugins/unobtrusive_javascript/lib/actionview_helpers_patches.rb +17 -0
- data/vendor/plugins/unobtrusive_javascript/lib/asset_tag_helper_patches.rb +33 -0
- data/vendor/plugins/unobtrusive_javascript/lib/behaviour_caching.rb +70 -0
- data/vendor/plugins/unobtrusive_javascript/lib/controllers/unobtrusive_javascript_controller.rb +52 -0
- data/vendor/plugins/unobtrusive_javascript/lib/prototype_helper_patches.rb +72 -0
- data/vendor/plugins/unobtrusive_javascript/lib/scriptaculous_helper_patches.rb +62 -0
- data/vendor/plugins/unobtrusive_javascript/lib/tag_helper_patches.rb +37 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs.rb +32 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/behaviour_helper.rb +62 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/behaviour_script.rb +54 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/behaviour_script_converter.rb +23 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/controller_methods.rb +55 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/helpers.rb +152 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/javascript_proxies.rb +57 -0
- data/vendor/plugins/unobtrusive_javascript/tasks/unobtrusive_javascript_tasks.rake +15 -0
- data/vendor/plugins/unobtrusive_javascript/test/asset_tag_helper_patches_test.rb +32 -0
- data/vendor/plugins/unobtrusive_javascript/test/behaviour_helper_test.rb +180 -0
- data/vendor/plugins/unobtrusive_javascript/test/behaviour_script_converter_test.rb +72 -0
- data/vendor/plugins/unobtrusive_javascript/test/behaviour_script_test.rb +98 -0
- data/vendor/plugins/unobtrusive_javascript/test/config/environment.rb +8 -0
- data/vendor/plugins/unobtrusive_javascript/test/config/routes.rb +4 -0
- data/vendor/plugins/unobtrusive_javascript/test/config/schema.rb +3 -0
- data/vendor/plugins/unobtrusive_javascript/test/controller_methods_test.rb +48 -0
- data/vendor/plugins/unobtrusive_javascript/test/helpers_test.rb +186 -0
- data/vendor/plugins/unobtrusive_javascript/test/javascript_proxies_test.rb +3 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/boot.rb +26 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/action_controller.rb +11 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/action_mailer.rb +4 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/active_record.rb +27 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/rails.rb +31 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/ptk.rb +148 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/suite/difference.rb +23 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/stubs/controller_stub.rb +10 -0
- data/vendor/plugins/unobtrusive_javascript/test/ptk_helper.rb +29 -0
- data/vendor/plugins/unobtrusive_javascript/test/tag_helper_patches_test.rb +59 -0
- data/vendor/plugins/unobtrusive_javascript/test/test_helper.rb +25 -0
- data/vendor/plugins/unobtrusive_javascript/test/unobtrusive_javascript_controller_test.rb +95 -0
- data/vendor/plugins/unobtrusive_javascript/uninstall.rb +1 -0
- data/vendor/redcloth/bin/redcloth +3 -0
- data/vendor/redcloth/doc/CHANGELOG +160 -0
- data/vendor/redcloth/doc/COPYING +25 -0
- data/vendor/redcloth/doc/README +106 -0
- data/vendor/redcloth/doc/REFERENCE +216 -0
- data/vendor/redcloth/doc/make.rb +359 -0
- data/vendor/redcloth/lib/redcloth.rb +1130 -0
- data/vendor/redcloth/run-tests.rb +28 -0
- data/vendor/redcloth/setup.rb +1376 -0
- data/vendor/redcloth/tests/code.yml +105 -0
- data/vendor/redcloth/tests/hard_breaks.yml +26 -0
- data/vendor/redcloth/tests/images.yml +171 -0
- data/vendor/redcloth/tests/instiki.yml +39 -0
- data/vendor/redcloth/tests/links.yml +155 -0
- data/vendor/redcloth/tests/lists.yml +77 -0
- data/vendor/redcloth/tests/markdown.yml +218 -0
- data/vendor/redcloth/tests/poignant.yml +64 -0
- data/vendor/redcloth/tests/table.yml +198 -0
- data/vendor/redcloth/tests/textism.yml +406 -0
- metadata +432 -0
data/script/about
ADDED
data/script/breakpointer
ADDED
data/script/console
ADDED
data/script/destroy
ADDED
data/script/generate
ADDED
data/script/plugin
ADDED
data/script/runner
ADDED
data/script/server
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'contents_controller'
|
3
|
+
|
4
|
+
# Re-raise errors caught by the controller.
|
5
|
+
class ContentsController; def rescue_action(e) raise e end; end
|
6
|
+
|
7
|
+
class ContentsControllerTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@controller = ContentsController.new
|
10
|
+
@request = ActionController::TestRequest.new
|
11
|
+
@response = ActionController::TestResponse.new
|
12
|
+
end
|
13
|
+
|
14
|
+
# Replace this with your real tests.
|
15
|
+
def test_truth
|
16
|
+
assert true
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'pages_controller'
|
3
|
+
|
4
|
+
# Re-raise errors caught by the controller.
|
5
|
+
class PagesController; def rescue_action(e) raise e end; end
|
6
|
+
|
7
|
+
class PagesControllerTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@controller = PagesController.new
|
10
|
+
@request = ActionController::TestRequest.new
|
11
|
+
@response = ActionController::TestResponse.new
|
12
|
+
end
|
13
|
+
|
14
|
+
# Replace this with your real tests.
|
15
|
+
def test_truth
|
16
|
+
assert true
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'render_controller'
|
3
|
+
|
4
|
+
# Re-raise errors caught by the controller.
|
5
|
+
class RenderController; def rescue_action(e) raise e end; end
|
6
|
+
|
7
|
+
class RenderControllerTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@controller = RenderController.new
|
10
|
+
@request = ActionController::TestRequest.new
|
11
|
+
@response = ActionController::TestResponse.new
|
12
|
+
end
|
13
|
+
|
14
|
+
# Replace this with your real tests.
|
15
|
+
def test_truth
|
16
|
+
assert true
|
17
|
+
end
|
18
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
+
require 'test_help'
|
4
|
+
|
5
|
+
class Test::Unit::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
|
+
self.use_transactional_fixtures = true
|
19
|
+
|
20
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
21
|
+
# would need people(:david). If you don't want to migrate your existing
|
22
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
23
|
+
# instantiated fixtures translates to a database query per test method),
|
24
|
+
# then set this back to true.
|
25
|
+
self.use_instantiated_fixtures = false
|
26
|
+
|
27
|
+
# Add more helper methods to be used by all tests here...
|
28
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2006 Gabriel Gironda
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
19
|
+
DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,193 @@
|
|
1
|
+
== About
|
2
|
+
|
3
|
+
This plugin provides an easy way to give your ActiveRecord models clean urlnames, for
|
4
|
+
use anywhere you don't want to use a plain old integer id.
|
5
|
+
|
6
|
+
To use it, first either copy over the migration in <tt>db/00x_add_urlnames_table.rb</tt>
|
7
|
+
and migrate it to it, or import the SQL in <tt>db/urlnames_table.sql</tt>.
|
8
|
+
|
9
|
+
This plugin also requires at least Rails 1.1 (currently edge. See http://wiki.rubyonrails.com/rails/pages/EdgeRails)
|
10
|
+
For updates see http://gabriel.gironda.org, and for licensing see LICENSE.
|
11
|
+
|
12
|
+
Version: 0.5
|
13
|
+
|
14
|
+
----
|
15
|
+
|
16
|
+
== Simple usage:
|
17
|
+
|
18
|
+
=== Setting the url name
|
19
|
+
|
20
|
+
The usage that will work for 80% of cases is this:
|
21
|
+
|
22
|
+
class Article < ActiveRecord::Base
|
23
|
+
acts_as_urlnameable :title
|
24
|
+
end
|
25
|
+
|
26
|
+
This will format the value of the +title+ attribute of the record to one suitable for
|
27
|
+
use in a URL and save it. Further changes to +title+ will not overwrite the url name.
|
28
|
+
The value can then be accessed with +object.urlname+. If the url name already exists,
|
29
|
+
an error will be added to the +urlname+ attribute.
|
30
|
+
|
31
|
+
To allow overwrites of the url name, call +acts_as_urlname+ with the following option:
|
32
|
+
|
33
|
+
class Article < ActiveRecord::Base
|
34
|
+
acts_as_urlnameable :title, :overwrite => true
|
35
|
+
end
|
36
|
+
|
37
|
+
=== Validation
|
38
|
+
|
39
|
+
The url name will now be overwritten if the value of +title+ changes. To change the
|
40
|
+
default validation message you can use the <tt>:message</tt> option:
|
41
|
+
|
42
|
+
class Article < ActiveRecord::Base
|
43
|
+
acts_as_urlnameable :title, :overwrite => true, :message => 'is unavailable.'
|
44
|
+
end
|
45
|
+
|
46
|
+
=== Finding records
|
47
|
+
|
48
|
+
Records can be located via the +find_by_urlname+ method, like so:
|
49
|
+
|
50
|
+
Article.find_by_urlname('some_urlname')
|
51
|
+
|
52
|
+
|
53
|
+
----
|
54
|
+
|
55
|
+
== Advanced usage:
|
56
|
+
|
57
|
+
This section is for those of us who like to mess with ActiveRecord a little more than
|
58
|
+
usual.
|
59
|
+
|
60
|
+
=== Setting the url name
|
61
|
+
|
62
|
+
You can set objects to be known by any past url names they may have had, even if the
|
63
|
+
current one is different. The usage in this case would be:
|
64
|
+
|
65
|
+
class Article < ActiveRecord::Base
|
66
|
+
acts_as_urlnameable :title, :mode => :multiple
|
67
|
+
end
|
68
|
+
|
69
|
+
The instance method +past_urlnames+ will then return all url names other than the current
|
70
|
+
one, while +all_urlnames+ will return all url names the object has ever been known by,
|
71
|
+
including the current url name. The <tt>:overwrite</tt> option has no effect on objects
|
72
|
+
with multiple urlnames for obvious reasons.
|
73
|
+
|
74
|
+
You can also define your own <tt>urlnameify</tt> method if you would prefer not to use the
|
75
|
+
default url name formatting.
|
76
|
+
|
77
|
+
class Article < ActiveRecord::Base
|
78
|
+
acts_as_urlnameable :title, :mode => :multiple
|
79
|
+
|
80
|
+
protected
|
81
|
+
def urlnameify(text)
|
82
|
+
text.to_s.downcase + '_permalink'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
=== Validation
|
87
|
+
|
88
|
+
Acts as Urlnameable gives you five options for validation:
|
89
|
+
|
90
|
+
* Skip any kind of validation (usually undesirable)
|
91
|
+
* Validating against the base class (the default)
|
92
|
+
* Validating against the child class (for use with single table inheritance)
|
93
|
+
* Validating against the parent object (for associations)
|
94
|
+
* Define your own validate_urlname method
|
95
|
+
|
96
|
+
==== Skipping validation
|
97
|
+
|
98
|
+
To skip validation, use the plugin like so:
|
99
|
+
|
100
|
+
class Article < ActiveRecord::Base
|
101
|
+
acts_as_urlnameable :title, :mode => :multiple, :validate => false
|
102
|
+
end
|
103
|
+
|
104
|
+
==== Validating against the base class or child class
|
105
|
+
|
106
|
+
If you're using single table inheritance in ActiveRecord, and your models look like this for example:
|
107
|
+
|
108
|
+
class Article < ActiveRecord::Base
|
109
|
+
acts_as_urlnameable :title
|
110
|
+
end
|
111
|
+
|
112
|
+
class SpecialArticle < Article
|
113
|
+
end
|
114
|
+
|
115
|
+
class Draft < Article
|
116
|
+
end
|
117
|
+
|
118
|
+
Then by default, a Draft can not have the same url name as a SpecialArticle. If you'd like to change
|
119
|
+
this behaviour, then use the <tt>:sti_class</tt> option with <tt>:validate</tt>
|
120
|
+
|
121
|
+
class Article < ActiveRecord::Base
|
122
|
+
acts_as_urlnameable :title, :validate => :sti_class
|
123
|
+
end
|
124
|
+
|
125
|
+
Now Draft and SpecialArticle can have the same url name set. <tt>SpecialArticle.find_by_urlname</tt>
|
126
|
+
will find only the SpecialArticle with the matching url name, and <tt>Draft.find_by_urlname</tt> will
|
127
|
+
find only the Draft with the url name given.
|
128
|
+
|
129
|
+
<tt>Article.find_by_urlname</tt> will find the first Article with the given url name, whereas <tt>Article.find_all_by_urlname</tt>
|
130
|
+
will find both the Draft and SpecialArticle objects.
|
131
|
+
|
132
|
+
==== Validating against the parent object
|
133
|
+
|
134
|
+
Here's an example model setup:
|
135
|
+
|
136
|
+
class Person < ActiveRecord::Base
|
137
|
+
has_many :articles
|
138
|
+
end
|
139
|
+
|
140
|
+
class Article < ActiveRecord::Base
|
141
|
+
acts_as_urlnameable :title
|
142
|
+
belongs_to :person
|
143
|
+
end
|
144
|
+
|
145
|
+
If you would like to validate the url name for an article against the parent object, pass the name
|
146
|
+
of the <tt>belongs_to</tt> association as the option for <tt>:validate</tt>. Example:
|
147
|
+
|
148
|
+
class Article < ActiveRecord::Base
|
149
|
+
acts_as_urlnameable :title, :validate => :person
|
150
|
+
belongs_to :person
|
151
|
+
end
|
152
|
+
|
153
|
+
Now for the validation to work properly, you must instantiate the new article through the association.
|
154
|
+
This is best explained like this:
|
155
|
+
|
156
|
+
# Find two different people
|
157
|
+
bob = Person.find_by_first_name('bob')
|
158
|
+
joe = Person.find_by_first_name('joe')
|
159
|
+
|
160
|
+
# Have Bob write a new article
|
161
|
+
bobs_article = bob.articles.build(:title => "My first article", :body => "This is my first article")
|
162
|
+
bobs_article.save # passes validation and saves ok
|
163
|
+
|
164
|
+
# Have Joe write a new article
|
165
|
+
joes_article = joe.articles.build(:title => "My first article", :body => "This is my first article")
|
166
|
+
joes_article.save # passes validation and saves ok
|
167
|
+
|
168
|
+
# Find Bob's first article
|
169
|
+
bob.articles.find_by_urlname('my_first_article')
|
170
|
+
|
171
|
+
# Find Joe's first article
|
172
|
+
joe.articles.find_by_urlname('my_first_article')
|
173
|
+
|
174
|
+
Both articles validate because the validation is scoped against the owner. Bob and Joe can both have
|
175
|
+
articles known as 'my_first_article', and the finder method will find only their own articles.
|
176
|
+
<tt>Article.find_all_by_urlname('my_first_article')</tt> will find both articles.
|
177
|
+
|
178
|
+
==== Custom validation
|
179
|
+
|
180
|
+
You can also define your own validate_urlname method in the class for custom validation, like so:
|
181
|
+
|
182
|
+
class Person < ActiveRecord::Base
|
183
|
+
acts_as_urlnameable :first_name
|
184
|
+
|
185
|
+
protected
|
186
|
+
def validate_urlname
|
187
|
+
if Person.find_by_urlname(attr_to_urlname)
|
188
|
+
errors.add(:urlname, 'is not available.')
|
189
|
+
elsif attr_to_urlname == 'bob'
|
190
|
+
errors.add_to_base('You might be Bob, and I hate Bob.')
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|