infopark_rails_connector 6.8.0.beta.200.621.4c8e1b0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/README +59 -0
  2. data/app/assets/images/admin/minus.gif +0 -0
  3. data/app/assets/images/bg80.png +0 -0
  4. data/app/assets/images/edit.png +0 -0
  5. data/app/assets/images/icons/mm_generic.png +0 -0
  6. data/app/assets/images/icons/mm_menu.png +0 -0
  7. data/app/assets/images/ratings/star.gif +0 -0
  8. data/app/assets/images/time_machine/calendar-menuarrow.gif +0 -0
  9. data/app/assets/images/time_machine/calendar_bg.png +0 -0
  10. data/app/assets/images/time_machine/icon.png +0 -0
  11. data/app/assets/images/time_machine/slider_bg.png +0 -0
  12. data/app/assets/images/time_machine/slider_handle.png +0 -0
  13. data/app/assets/images/time_machine/timemachine_bg.png +0 -0
  14. data/app/assets/javascripts/comments.js +29 -0
  15. data/app/assets/javascripts/editmarker.js +240 -0
  16. data/app/assets/javascripts/infopark_rails_connector.js.erb +3 -0
  17. data/app/assets/javascripts/initializer.js +9 -0
  18. data/app/assets/javascripts/ratings.js +26 -0
  19. data/app/assets/javascripts/time_machine/calendar-setup.js +200 -0
  20. data/app/assets/javascripts/time_machine/calendar.js +1806 -0
  21. data/app/assets/javascripts/time_machine/lang/calendar-de.js +127 -0
  22. data/app/assets/javascripts/time_machine/lang/calendar-en.js +127 -0
  23. data/app/assets/javascripts/time_machine/lang/calendar-es.js +129 -0
  24. data/app/assets/javascripts/time_machine/lang/calendar-fr.js +125 -0
  25. data/app/assets/javascripts/time_machine/lang/calendar-it.js +124 -0
  26. data/app/assets/javascripts/time_machine/slider.js +278 -0
  27. data/app/assets/javascripts/time_machine.js +8 -0
  28. data/app/assets/stylesheets/editmarker.css +70 -0
  29. data/app/assets/stylesheets/infopark_rails_connector.css.erb +4 -0
  30. data/app/assets/stylesheets/ratings.css +97 -0
  31. data/app/assets/stylesheets/time_machine/time_machine.css +292 -0
  32. data/app/assets/stylesheets/time_machine.css +6 -0
  33. data/app/controllers/cms_controller.rb +6 -0
  34. data/app/controllers/comments_controller.rb +6 -0
  35. data/app/controllers/crm_form_controller.rb +2 -0
  36. data/app/controllers/pdf_controller.rb +6 -0
  37. data/app/controllers/rails_connector/default_cms_controller.rb +40 -0
  38. data/app/controllers/rails_connector/default_comments_controller.rb +71 -0
  39. data/app/controllers/rails_connector/default_crm_form_controller.rb +167 -0
  40. data/app/controllers/rails_connector/default_pdf_controller.rb +136 -0
  41. data/app/controllers/rails_connector/default_ratings_controller.rb +84 -0
  42. data/app/controllers/rails_connector/default_rss_controller.rb +29 -0
  43. data/app/controllers/rails_connector/default_search_controller.rb +60 -0
  44. data/app/controllers/rails_connector/default_user_controller.rb +267 -0
  45. data/app/controllers/rails_connector/pdf_external_controller.rb +54 -0
  46. data/app/controllers/rails_connector/time_machine_controller.rb +48 -0
  47. data/app/controllers/ratings_controller.rb +6 -0
  48. data/app/controllers/rss_controller.rb +6 -0
  49. data/app/controllers/search_controller.rb +2 -0
  50. data/app/controllers/seo_sitemap_controller.rb +12 -0
  51. data/app/controllers/user_controller.rb +2 -0
  52. data/app/helpers/cms_helper.rb +6 -0
  53. data/app/helpers/cms_routing_helper.rb +6 -0
  54. data/app/helpers/crm_form_helper.rb +3 -0
  55. data/app/helpers/rails_connector/cms_asset_helper.rb +51 -0
  56. data/app/helpers/rails_connector/default_cms_helper.rb +27 -0
  57. data/app/helpers/rails_connector/default_cms_routing_helper.rb +93 -0
  58. data/app/helpers/rails_connector/default_crm_form_helper.rb +58 -0
  59. data/app/helpers/rails_connector/default_ratings_helper.rb +38 -0
  60. data/app/helpers/rails_connector/default_user_helper.rb +90 -0
  61. data/app/helpers/rails_connector/display_helper.rb +117 -0
  62. data/app/helpers/rails_connector/error_messages_helper.rb +23 -0
  63. data/app/helpers/rails_connector/layout_helper.rb +30 -0
  64. data/app/helpers/rails_connector/link_helper.rb +88 -0
  65. data/app/helpers/rails_connector/mandatory_label_helper.rb +10 -0
  66. data/app/helpers/rails_connector/marker_helper.rb +363 -0
  67. data/app/helpers/rails_connector/menu_helper.rb +72 -0
  68. data/app/helpers/rails_connector/micronav_helper.rb +107 -0
  69. data/app/helpers/rails_connector/seo_helper.rb +44 -0
  70. data/app/helpers/rails_connector/table_of_contents_helper.rb +20 -0
  71. data/app/helpers/rails_connector/time_machine_helper.rb +24 -0
  72. data/app/helpers/rails_connector/tracking_helper.rb +32 -0
  73. data/app/helpers/ratings_helper.rb +4 -0
  74. data/app/helpers/user_helper.rb +3 -0
  75. data/app/mailers/confirmation_mailer.rb +13 -0
  76. data/app/models/crm_form.rb +2 -0
  77. data/app/models/named_link.rb +2 -0
  78. data/app/models/obj.rb +9 -0
  79. data/app/models/rails_connector/default_comment.rb +28 -0
  80. data/app/models/rails_connector/default_rating.rb +20 -0
  81. data/app/models/rails_connector/link_list.rb +30 -0
  82. data/app/views/cms/_comments.html.erb +44 -0
  83. data/app/views/cms/_index.html.erb +7 -0
  84. data/app/views/cms/_rating.html.erb +31 -0
  85. data/app/views/cms/index.html.erb +3 -0
  86. data/app/views/comments/_comment.html.erb +28 -0
  87. data/app/views/confirmation_mailer/register_confirmation.erb +5 -0
  88. data/app/views/confirmation_mailer/reset_password.erb +5 -0
  89. data/app/views/crm_form/_flash_messages.html.erb +11 -0
  90. data/app/views/crm_form/_form.html.erb +17 -0
  91. data/app/views/crm_form/confirmation.html.erb +3 -0
  92. data/app/views/crm_form/index.html.erb +5 -0
  93. data/app/views/crm_form/not_logged_in.html.erb +1 -0
  94. data/app/views/errors/403_forbidden.html.erb +3 -0
  95. data/app/views/errors/410_gone.html.erb +7 -0
  96. data/app/views/layouts/rails_connector/time_machine.html.erb +12 -0
  97. data/app/views/pdf/index.html.erb +7 -0
  98. data/app/views/pdf/index.xsl +1240 -0
  99. data/app/views/rails_connector/time_machine/index.html.erb +88 -0
  100. data/app/views/rss/_item.rss.builder +11 -0
  101. data/app/views/rss/index.rss.builder +11 -0
  102. data/app/views/search/_hit.html.erb +12 -0
  103. data/app/views/search/_hits.html.erb +11 -0
  104. data/app/views/search/_mini_panel.html.erb +4 -0
  105. data/app/views/search/_pagination.html.erb +5 -0
  106. data/app/views/search/_panel.html.erb +4 -0
  107. data/app/views/search/search.html.erb +12 -0
  108. data/app/views/seo_sitemap/show.xml.builder +16 -0
  109. data/app/views/user/_flash_messages.html.erb +11 -0
  110. data/app/views/user/edit.html.erb +6 -0
  111. data/app/views/user/edit_password.html.erb +11 -0
  112. data/app/views/user/forgot_password.html.erb +7 -0
  113. data/app/views/user/login.html.erb +15 -0
  114. data/app/views/user/new.html.erb +11 -0
  115. data/app/views/user/profile.html.erb +8 -0
  116. data/app/views/user/register_pending.html.erb +1 -0
  117. data/app/views/user/set_password.html.erb +14 -0
  118. data/config/cms_routes.rb +13 -0
  119. data/config/locales/de.rails_connector.controllers.yml +30 -0
  120. data/config/locales/de.rails_connector.errors.yml +11 -0
  121. data/config/locales/de.rails_connector.helpers.yml +9 -0
  122. data/config/locales/de.rails_connector.lib.yml +6 -0
  123. data/config/locales/de.rails_connector.models.yml +8 -0
  124. data/config/locales/de.rails_connector.views.yml +87 -0
  125. data/config/locales/en.rails_connector.controllers.yml +30 -0
  126. data/config/locales/en.rails_connector.errors.yml +10 -0
  127. data/config/locales/en.rails_connector.helpers.yml +9 -0
  128. data/config/locales/en.rails_connector.lib.yml +6 -0
  129. data/config/locales/en.rails_connector.models.yml +8 -0
  130. data/config/locales/en.rails_connector.views.yml +87 -0
  131. data/config/routes.rb +37 -0
  132. data/lib/generators/rails_connector/comments/comments_generator.rb +21 -0
  133. data/lib/generators/rails_connector/comments/templates/migration.rb +17 -0
  134. data/lib/generators/rails_connector/install/install_generator.rb +38 -0
  135. data/lib/generators/rails_connector/install/templates/initializers/rails_connector.rb +58 -0
  136. data/lib/generators/rails_connector/install/templates/local/configuration.rb +2 -0
  137. data/lib/generators/rails_connector/install/templates/obj_extensions.rb +25 -0
  138. data/lib/generators/rails_connector/ratings/ratings_generator.rb +21 -0
  139. data/lib/generators/rails_connector/ratings/templates/migration.rb +15 -0
  140. data/lib/infopark_rails_connector.rb +31 -0
  141. data/lib/obj_extensions.rb +6 -0
  142. data/lib/rails_connector/authenticable.rb +30 -0
  143. data/lib/rails_connector/cms_accessible.rb +114 -0
  144. data/lib/rails_connector/cms_dispatch_controller.rb +47 -0
  145. data/lib/rails_connector/cms_env.rb +55 -0
  146. data/lib/rails_connector/cms_test_request.rb +23 -0
  147. data/lib/rails_connector/commentable.rb +23 -0
  148. data/lib/rails_connector/configuration/google_analytics.rb +29 -0
  149. data/lib/rails_connector/configuration/pdf_generator.rb +15 -0
  150. data/lib/rails_connector/configuration/rss.rb +46 -0
  151. data/lib/rails_connector/configuration.rb +235 -0
  152. data/lib/rails_connector/core_extensions/time.rb +18 -0
  153. data/lib/rails_connector/core_extensions.rb +1 -0
  154. data/lib/rails_connector/crm.rb +282 -0
  155. data/lib/rails_connector/engine.rb +78 -0
  156. data/lib/rails_connector/fop.rb +18 -0
  157. data/lib/rails_connector/fop_on_rails/document/dom_tree.rb +42 -0
  158. data/lib/rails_connector/fop_on_rails/document/images.rb +34 -0
  159. data/lib/rails_connector/fop_on_rails/document/tables.rb +67 -0
  160. data/lib/rails_connector/fop_on_rails/document.rb +25 -0
  161. data/lib/rails_connector/fop_on_rails.rb +92 -0
  162. data/lib/rails_connector/googlebot_checker.rb +47 -0
  163. data/lib/rails_connector/html_string.rb +19 -0
  164. data/lib/rails_connector/infopark_base.rb +2 -0
  165. data/lib/rails_connector/link_resolvable.rb +9 -0
  166. data/lib/rails_connector/liquid_support/action_marker.rb +69 -0
  167. data/lib/rails_connector/liquid_support/field_value_drop.rb +22 -0
  168. data/lib/rails_connector/liquid_support/general_helper_tag.rb +44 -0
  169. data/lib/rails_connector/liquid_support/link_drop.rb +22 -0
  170. data/lib/rails_connector/liquid_support/liquid_template_handler.rb +162 -0
  171. data/lib/rails_connector/liquid_support/named_object_drop.rb +14 -0
  172. data/lib/rails_connector/liquid_support/obj_drop.rb +43 -0
  173. data/lib/rails_connector/liquid_support/obj_filters.rb +77 -0
  174. data/lib/rails_connector/liquid_support.rb +23 -0
  175. data/lib/rails_connector/markdown_string.rb +19 -0
  176. data/lib/rails_connector/rateable.rb +57 -0
  177. data/lib/rails_connector/seo.rb +52 -0
  178. data/lib/rails_connector/ses.rb +72 -0
  179. data/lib/rails_connector/string_tagging.rb +29 -0
  180. data/lib/rails_connector/syndicateable.rb +11 -0
  181. data/lib/search_request.rb +2 -0
  182. data/lib/tasks/check.rake +25 -0
  183. data/lib/tasks/cms_license_check.rake +17 -0
  184. metadata +489 -0
data/config/routes.rb ADDED
@@ -0,0 +1,37 @@
1
+ Rails.application.routes.draw do
2
+ if RailsConnector::Configuration.enabled?(:search)
3
+ match 'search', :to => 'search#search'
4
+ end
5
+
6
+ if RailsConnector::Configuration.enabled?(:crm)
7
+ match 'login', :to => 'user#login'
8
+ match 'logout', :to => 'user#logout'
9
+ match 'user/:action', :to => 'user', :as => "user"
10
+ end
11
+
12
+ if RailsConnector::Configuration.enabled?(:time_machine) && RailsConnector::Configuration.editor_interface_enabled?
13
+ match 'time_machine/:action', :to => 'rails_connector/time_machine', :as => "time_machine"
14
+ end
15
+
16
+ if RailsConnector::Configuration.enabled?(:pdf_generator)
17
+ match 'pdf/external', :to => 'rails_connector/pdf_external#index', :as => "pdf_external"
18
+ match 'pdf/:id', :to => 'pdf#index', :as => "pdf"
19
+ match 'pdf/:action/:id', :to => 'pdf', :as => "pdf_with_action"
20
+ end
21
+
22
+ if RailsConnector::Configuration.enabled?(:rss)
23
+ match 'rss', :to => 'rss#index', :format => "rss"
24
+ end
25
+
26
+ if RailsConnector::Configuration.enabled?(:comments)
27
+ match 'comments/:action(/:id)', :to => 'comments', :as => "comment"
28
+ end
29
+
30
+ if RailsConnector::Configuration.enabled?(:ratings)
31
+ match 'ratings/:action/:id(/:score)', :to => 'ratings', :as => "ratings"
32
+ end
33
+
34
+ if RailsConnector::Configuration.enabled?(:seo_sitemap)
35
+ match 'sitemap.xml', :to => 'seo_sitemap#show', :format => 'xml'
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ #:stopdoc:
2
+ require "rails/generators/active_record"
3
+
4
+ module RailsConnector
5
+ module Generators
6
+ class CommentsGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+
9
+ source_root File.expand_path('../templates', __FILE__)
10
+
11
+ def self.next_migration_number(dirname)
12
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
13
+ end
14
+
15
+ desc "Create a migration to create comments in your application."
16
+ def generate_migration
17
+ migration_template 'migration.rb', 'db/migrate/create_comments.rb'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ # :stopdoc:
2
+ class CreateComments < ActiveRecord::Migration
3
+ def self.up
4
+ create_table :comments do |t|
5
+ t.string :obj_id
6
+ t.string :name
7
+ t.string :email
8
+ t.string :subject
9
+ t.text :body
10
+ t.datetime :created_at
11
+ end
12
+ end
13
+
14
+ def self.down
15
+ drop_table :comments
16
+ end
17
+ end
@@ -0,0 +1,38 @@
1
+ #:stopdoc:
2
+ module RailsConnector
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+ desc "Copy Infopark Rails Connector files to your application."
6
+
7
+ # Normally, you'd just call 'source_root' as a class method from here,
8
+ # but we need to glob the dir ourselves. Hence our own method.
9
+ def self.source_root
10
+ @source_root ||= File.expand_path('../templates', __FILE__)
11
+ end
12
+
13
+ def install_configuration
14
+ copy_file "initializers/rails_connector.rb", "config/initializers/rails_connector.rb"
15
+ copy_file "obj_extensions.rb", "lib/obj_extensions.rb"
16
+ copy_file "local/configuration.rb", "config/local/configuration.rb"
17
+ end
18
+
19
+ def append_asset_manifests
20
+ append_file("app/assets/javascripts/application.js", "//= require infopark_rails_connector")
21
+ gsub_file("app/assets/stylesheets/application.css", "*= require_tree .",
22
+ "*= require_tree .\n *= require infopark_rails_connector")
23
+ end
24
+
25
+ def remove_public_index_html
26
+ remove_file "public/index.html"
27
+ remove_file "app/assets/images/rails.png"
28
+ end
29
+
30
+ def patch_default_application_layout
31
+ gsub_file("app/views/layouts/application.html.erb", %r{</head>},
32
+ "<%= rails_connector_header_tags %>\n</head>")
33
+ gsub_file("app/views/layouts/application.html.erb", %r{</body>},
34
+ "<%= rails_connector_after_content_tags %>\n</body>")
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,58 @@
1
+ # Name of the CMS Fiona Instance to access
2
+ RailsConnector::Configuration.instance_name = 'default'
3
+
4
+ # Enable Rails Connector Addons.
5
+ # Please refer to the Infopark Knowledge Base for more information on addons.
6
+ RailsConnector::Configuration.enable(
7
+ # :comments,
8
+ # :google_analytics,
9
+ # :crm,
10
+ # :pdf_generator,
11
+ # :ratings,
12
+ # :rss,
13
+ :search,
14
+ # :seo_sitemap,
15
+ :time_machine
16
+ )
17
+
18
+ # Search should be configured in config/rails_connector.yml
19
+
20
+ # RSS-Feed:
21
+ #
22
+ # Specify which Object should be used for the RSS feed's parent folder
23
+ # RailsConnector::Configuration::Rss.root = lambda { NamedLink.get_object('news') }
24
+
25
+
26
+ # PDF-Generator:
27
+ #
28
+ # Set a list of approved hosts which the PdfGenerator is allowed to use
29
+ RailsConnector::Configuration::PdfGenerator.host_whitelist('localhost')
30
+
31
+
32
+ # Google Analytics:
33
+ #
34
+ # RailsConnector::Configuration::GoogleAnalytics.domains(
35
+ # '<your.domain.com>' => '<your-ga-code-1>',
36
+ # '<your.domain.de>' => '<your-ga-code-2>'
37
+ # )
38
+
39
+ # OMC:
40
+ #
41
+ # Infopark::Crm.configure do |config|
42
+ # config.url = "http://<crm-domain>:<port>"
43
+ # config.login = 'webservice'
44
+ # config.api_key = '<password>'
45
+ # # config.live_server_groups_callback = lambda {|contact|
46
+ # # case contact.account.name
47
+ # # when "My Company"
48
+ # # %w(internal)
49
+ # # else
50
+ # # []
51
+ # # end
52
+ # # }
53
+ # end
54
+ #
55
+ # Re-captcha public/private key pair (used for creating a new user)
56
+ # You can get those by signing up at http://recaptcha.net/
57
+ # RCC_PUB=""
58
+ # RCC_PRIV=""
@@ -0,0 +1,2 @@
1
+ # Put your local configuration here.
2
+ # Don't forget to configure your SCM to ignore this file.
@@ -0,0 +1,25 @@
1
+ module ObjExtensions
2
+
3
+ # Infopark Rails Connector enables the developer to define specific behavior for Fiona CMS
4
+ # classes by using Single Table Inheritance (http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html).
5
+ #
6
+ # If you wish to decorate the Obj model with extra behavior, you will need to add it here.
7
+ #
8
+ # Be careful only to use methods and classes that are part of the documented api.
9
+ # Other methods and classes may change without warning.
10
+
11
+ def self.enable
12
+ return if Obj.respond_to? :obj_extensions_enabled
13
+
14
+ Obj.class_eval do
15
+
16
+ def self.obj_extensions_enabled
17
+ end
18
+
19
+ # Add custom extensions to the Obj model below
20
+ #
21
+
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ #:stopdoc:
2
+ require "rails/generators/active_record"
3
+
4
+ module RailsConnector
5
+ module Generators
6
+ class RatingsGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+
9
+ source_root File.expand_path('../templates', __FILE__)
10
+
11
+ def self.next_migration_number(dirname)
12
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
13
+ end
14
+
15
+ desc "Copy files to your application and create a migration to create ratings."
16
+ def generate_migration
17
+ migration_template 'migration.rb', 'db/migrate/create_ratings.rb'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # :stopdoc:
2
+ class CreateRatings < ActiveRecord::Migration
3
+ def self.up
4
+ create_table :ratings do |t|
5
+ t.timestamps
6
+ t.column :obj_id, :string
7
+ t.column :score, :integer
8
+ t.column :count, :integer, :default => 0
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :ratings
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ module ::RailsConnector
2
+ def self.load_platform_gem_if_present(name) # :nodoc:
3
+ if Gem.loaded_specs["infopark_#{name}_connector"]
4
+ gem_name = "infopark_#{name}_connector"
5
+
6
+ # ensure the other connector is present in exactly the same version
7
+ gem gem_name, Gem.loaded_specs["infopark_rails_connector"].version
8
+
9
+ require gem_name
10
+
11
+ @platform = name
12
+ end
13
+ end
14
+
15
+ # return either :fiona or :cloud depending on the app's configuration.
16
+ def self.platform
17
+ @platform
18
+ end
19
+ end
20
+
21
+ RailsConnector::load_platform_gem_if_present(:cloud)
22
+ RailsConnector::load_platform_gem_if_present(:fiona)
23
+
24
+ unless RailsConnector::platform
25
+ raise "The infopark_rails_connector gem requires "\
26
+ "either the infopark_cloud_connector gem (for use with Infopark Cloud Express) or "\
27
+ "the infopark_fiona_connector gem (for use with Infopark CMS Fiona). "\
28
+ "Add either gem to your Gemfile."
29
+ end
30
+
31
+ require "rails_connector/engine" if defined?(Rails)
@@ -0,0 +1,6 @@
1
+ # empty implementation for ObjExtension
2
+ # only unsed in case the app does not define ObjExtensions itself
3
+ module ObjExtensions
4
+ def self.enable
5
+ end
6
+ end
@@ -0,0 +1,30 @@
1
+ module RailsConnector
2
+ module Authenticable #:nodoc:
3
+ def self.included(mod)
4
+ %w(logged_in? admin? current_user).each do |method_name|
5
+ unless instance_method_defined?(mod, method_name)
6
+ mod.class_eval do
7
+ private
8
+ define_method(method_name, InstanceMethods.method(method_name).to_proc)
9
+ end
10
+ end
11
+
12
+ mod.send(:helper_method, method_name)
13
+ end
14
+ end
15
+
16
+ module InstanceMethods #:nodoc:
17
+ def self.logged_in?; false; end
18
+ def self.admin?; false; end
19
+ def self.current_user; nil; end
20
+ end
21
+
22
+ private
23
+
24
+ def self.instance_method_defined?(mod, method_name)
25
+ mod.instance_methods.include?(method_name) or
26
+ mod.protected_instance_methods.include?(method_name) or
27
+ mod.private_instance_methods.include?(method_name)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,114 @@
1
+ module RailsConnector
2
+
3
+ module CmsAccessible
4
+
5
+ protected
6
+
7
+ def set_preview_time # :nodoc:
8
+ Obj.preview_time = session[:preview_time]
9
+ end
10
+
11
+ # Filter method to load a CMS object.
12
+ #
13
+ # To require the loading for all actions, use this in your controllers:
14
+ # before_filter :load_object
15
+ def load_object # :nodoc:
16
+ CmsEnv.new(request.env).load
17
+ loaded_obj = request.env[CmsEnv::OBJ_ENV_KEY]
18
+ raise loaded_obj if loaded_obj.is_a?(RailsConnector::ResourceNotFound)
19
+ @obj = loaded_obj
20
+ end
21
+
22
+ # Filter method to check if the already loaded object is active. If it is
23
+ # not, a 410 Gone error message will be generate (by calling render_obj_error).
24
+ #
25
+ # To require the check for all actions, use this in your controllers:
26
+ # before_filter :load_object
27
+ # before_filter :ensure_object_is_active
28
+ def ensure_object_is_active # :nodoc:
29
+ unless @obj.active?
30
+ @valid_from = @obj.valid_from
31
+ @valid_until = @obj.valid_until
32
+ @obj = nil
33
+ render_obj_error(410, "gone")
34
+ return false
35
+ end
36
+ return true
37
+ end
38
+
39
+ # Filter method to check if access to the loaded object is permitted. If it is
40
+ # not, a 403 Forbidden error message will be generated (by calling render_obj_error)
41
+ #
42
+ # To require the check for all actions, use this in your controllers:
43
+ # before_filter :load_object
44
+ # before_filter :ensure_object_is_permitted
45
+ def ensure_object_is_permitted # :nodoc:
46
+ unless is_permitted(@obj)
47
+ @obj = nil
48
+ render_obj_error(403, "forbidden")
49
+ return false
50
+ end
51
+ return true
52
+ end
53
+
54
+ # This method is called when rendering an error caused by either ensure_object_is_permitted
55
+ # or ensure_object_is_active before filter. It renders an error template located in
56
+ # "errors/*.html.erb" with given HTTP status and content type "text/html" and with no layout.
57
+ # Overwrite this method to change the error page.
58
+ def render_obj_error(status, name)
59
+ force_html_format
60
+ render(
61
+ :template => "errors/#{status}_#{name}",
62
+ :layout => false,
63
+ :status => status,
64
+ :content_type => Mime::HTML
65
+ )
66
+ end
67
+
68
+ # Enforce "html" as template format.
69
+ def force_html_format # :doc:
70
+ request.format = :html
71
+ end
72
+
73
+ # Inclusion hook to make is_permitted available as helper method.
74
+ def self.included(base) # :nodoc:
75
+ base.__send__ :helper_method, :is_permitted
76
+ end
77
+
78
+ # Helper method to check live permissions
79
+ def is_permitted(obj) # :nodoc:
80
+ obj.permitted_for_user?(current_user)
81
+ end
82
+
83
+ # Filter method which sets the header 'X-Robots-Tag: unavailable_after'
84
+ # to the valid_until date of the current object.
85
+ def set_google_expire_header # :nodoc:
86
+ if @obj && (date = @obj.valid_until)
87
+ headers['X-Robots-Tag: unavailable_after'] = date.rfc822
88
+ end
89
+ end
90
+
91
+ # Deliver the obj's body as response by file or data.
92
+ # May respond with status 304 if a If-Modified-Since header is found.
93
+ def deliver_file
94
+ if @obj.body_data_url
95
+ redirect_to @obj.body_data_url
96
+ elsif stale?(:last_modified => @obj.last_changed.utc)
97
+ mime_type = @obj.mime_type
98
+ mime_type += '; charset=utf-8' if mime_type =~ /^text\//
99
+
100
+ if (filepath = @obj.body_data_path).present?
101
+ send_file(File.expand_path(filepath), {
102
+ :type => mime_type,
103
+ :filename => @obj.filename,
104
+ :disposition => 'inline',
105
+ })
106
+ else
107
+ # generics should send its body, empty files should be delivered as
108
+ # empty files - and not lead to an application error
109
+ send_data @obj.body || '', :type => mime_type, :filename => @obj.filename, :disposition => 'inline'
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,47 @@
1
+ #:enddoc:
2
+ module RailsConnector
3
+
4
+ class CmsDispatchController < ActionController::Metal
5
+ def process(action)
6
+ CmsEnv.new(env).load
7
+ controller = target_controller(env)
8
+ env["action_dispatch.request.path_parameters"]["controller"] = controller.controller_path
9
+
10
+ if !obj_not_found? && action == 'index'
11
+ action = loaded_obj.controller_action_name
12
+ end
13
+
14
+ env["action_dispatch.request.path_parameters"]["action"] = action
15
+
16
+ self.response = controller.action(action).call(env)
17
+ end
18
+
19
+ private
20
+
21
+ def target_controller(env)
22
+ return default_controller if obj_not_found?
23
+ controller = "#{loaded_obj.controller_name}Controller".constantize
24
+
25
+ if controller.respond_to?(:use_for_obj_dispatch?) && controller.use_for_obj_dispatch?
26
+ controller
27
+ else
28
+ default_controller
29
+ end
30
+ rescue NameError
31
+ default_controller
32
+ end
33
+
34
+ def loaded_obj
35
+ env[CmsEnv::OBJ_ENV_KEY]
36
+ end
37
+
38
+ def obj_not_found?
39
+ loaded_obj.is_a?(RailsConnector::ResourceNotFound)
40
+ end
41
+
42
+ def default_controller
43
+ CmsController
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,55 @@
1
+ #:enddoc:
2
+ module RailsConnector
3
+
4
+ class CmsEnv
5
+
6
+ OBJ_ENV_KEY = "INFOPARK_OBJ"
7
+
8
+ def initialize(env)
9
+ @env = env
10
+ end
11
+
12
+ def load
13
+ return if env[OBJ_ENV_KEY]
14
+ load_object
15
+ end
16
+
17
+ protected
18
+
19
+ attr_reader :env
20
+
21
+ def load_object
22
+ env[OBJ_ENV_KEY] =
23
+ begin
24
+ find_obj
25
+ rescue RailsConnector::ResourceNotFound => e
26
+ e
27
+ end
28
+ end
29
+
30
+ def find_obj
31
+ found_obj =
32
+ if params[:id]
33
+ Obj.find(params[:id])
34
+ elsif params[:permalink].present?
35
+ permalink = params[:permalink].to_a.join("/")
36
+ Obj.find_by_permalink!(permalink)
37
+ else
38
+ Obj.homepage
39
+ end
40
+
41
+ if found_obj.suppressed?
42
+ raise RailsConnector::ResourceNotFound,
43
+ "Tried to access Obj #{found_obj.inspect}, but it is suppressed (suppress_export is set)!"
44
+ end
45
+
46
+ found_obj
47
+ end
48
+
49
+ def params
50
+ env["action_dispatch.request.path_parameters"]
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,23 @@
1
+ module RailsConnector
2
+ module CmsTestRequest # :nodoc:
3
+ def for_cms_object(test_obj=nil)
4
+ # prepare the env as if the given obj was loaded by CmsEnv
5
+ env[RailsConnector::CmsEnv::OBJ_ENV_KEY] = test_obj if test_obj
6
+ class << self
7
+ # This special behaviour is necessary for testing controllers that descend from DefaultCmsController.
8
+ # These controllers do not have explicit routes by default.
9
+ # Instead, they are reached via the CmsDispatchController.
10
+ # The TestRequest must therefore use CmsDispatchController as a fallback route.
11
+ def assign_parameters(routes, controller_path, action, parameters = {})
12
+ super(routes, controller_path, action, parameters)
13
+ rescue ActionController::RoutingError=> e
14
+ begin
15
+ super(routes, "rails_connector/cms_dispatch", action, parameters)
16
+ rescue ActionController::RoutingError
17
+ raise e
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module RailsConnector
2
+ # This module is included if the <tt>:comments</tt> addon is
3
+ # enabled:
4
+ # RailsConnector::Configuration.enable(:comments)
5
+ module Commentable
6
+ # returns all Comments for this Obj.
7
+ def comments
8
+ Comment.where(:obj_id => id).order("created_at")
9
+ end
10
+
11
+ # Returns +true+ by default.
12
+ # Implement your own conditions by overwriting this method in your +ObjExtensions+.
13
+ def allow_comments?
14
+ true
15
+ end
16
+
17
+ # Returns +true+ by default.
18
+ # Implement your own conditions by overwriting this method in your +ObjExtensions+.
19
+ def allow_anonymous_comments?
20
+ true
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ module RailsConnector
2
+ class Configuration
3
+
4
+ # This module is an extension to the rails connector configuration.
5
+ #
6
+ # Configuration example:
7
+ #
8
+ # RailsConnector::Configuration::GoogleAnalytics.domains(
9
+ # 'www.example.de' => 'UA-example-1',
10
+ # 'www.example.com' => 'UA-example-2'
11
+ # )
12
+ module GoogleAnalytics
13
+ @@domains = {}
14
+
15
+ def self.domains=(domains_and_codes)
16
+ @@domains = @@domains.merge(domains_and_codes)
17
+ end
18
+
19
+ def self.domains(domains_and_codes)
20
+ self.domains = domains_and_codes
21
+ end
22
+
23
+ def self.domain_code(domain)
24
+ @@domains[domain]
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ module RailsConnector
2
+ class Configuration
3
+ module PdfGenerator
4
+ @@hosts = []
5
+
6
+ def self.host_whitelist(*hosts)
7
+ @@hosts = hosts
8
+ end
9
+
10
+ def self.host_allowed?(host)
11
+ @@hosts.include?(host)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,46 @@
1
+ module RailsConnector
2
+ class Configuration
3
+
4
+ # This module adds configuration options for the RSS feature.
5
+ #
6
+ # Specify the RSS root in
7
+ # <code><em>RAILS_ROOT</em>/config/initializers/rails_connector.rb</code>:
8
+ # RailsConnector::Configuration::Rss.root = lambda { NamedLink.get_object('news') }
9
+ module Rss
10
+
11
+ # Raised if no RSS root object has been specified.
12
+ class RootUndefined < StandardError; end
13
+ # Raised if the root is missing when accessing it
14
+ # Inherits from RootUndefined for compatibility reasons
15
+ class RootNotFound < RootUndefined; end
16
+
17
+ @root_provider = nil
18
+
19
+ # Stores the obj providing lambda for later use
20
+ def self.root=(obj_provider)
21
+ case obj_provider
22
+ when Obj
23
+ Rails.logger.warn("Rss.root= called with an Obj. Use an Obj returning lambda instead.")
24
+ root_id = obj_provider.id
25
+ @root_provider = lambda { Obj.find(root_id) }
26
+ when Proc
27
+ @root_provider = obj_provider
28
+ else
29
+ raise ArgumentError.new("Rss.root= called with '#{obj_provider.class.name}' instead of a lambda.")
30
+ end
31
+ end
32
+
33
+ # Returns the RSS root object.
34
+ # If no RSS root has been specified then Rss::RootUndefined is raised.
35
+ def self.root
36
+ raise RootUndefined unless @root_provider
37
+ begin
38
+ @root_provider.call
39
+ rescue RailsConnector::ResourceNotFound
40
+ raise RootNotFound
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+ end