infopark_rails_connector 6.9.2.1.125136549 → 6.9.3.1.36404185

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,37 +0,0 @@
1
- module RailsConnector
2
- module Generators
3
- class InstallGenerator < Rails::Generators::Base
4
- desc "Copy Infopark Rails Connector files to your application."
5
-
6
- # Normally, you'd just call 'source_root' as a class method from here,
7
- # but we need to glob the dir ourselves. Hence our own method.
8
- def self.source_root
9
- @source_root ||= File.expand_path('../templates', __FILE__)
10
- end
11
-
12
- def install_configuration
13
- copy_file "initializers/rails_connector.rb", "config/initializers/rails_connector.rb"
14
- template 'app/models/obj.rb.erb', 'app/models/obj.rb'
15
- copy_file "local/configuration.rb", "config/local/configuration.rb"
16
- end
17
-
18
- def append_asset_manifests
19
- append_file("app/assets/javascripts/application.js", "//= require infopark_rails_connector")
20
- gsub_file("app/assets/stylesheets/application.css", "*= require_tree .",
21
- "*= require_tree .\n *= require infopark_rails_connector")
22
- end
23
-
24
- def remove_public_index_html
25
- remove_file "public/index.html"
26
- remove_file "app/assets/images/rails.png"
27
- end
28
-
29
- def patch_default_application_layout
30
- gsub_file("app/views/layouts/application.html.erb", %r{</head>},
31
- "<%= rails_connector_header_tags %>\n</head>")
32
- gsub_file("app/views/layouts/application.html.erb", %r{</body>},
33
- "<%= rails_connector_after_content_tags %>\n</body>")
34
- end
35
- end
36
- end
37
- end
@@ -1,5 +0,0 @@
1
- # This is the base class for accessing CMS objects.
2
- # See the documentation for details: http://rubydoc.info/gems/infopark_<%= RailsConnector.platform %>_connector/RailsConnector/BasicObj
3
- class Obj < RailsConnector::BasicObj
4
- # Your custom code goes here...
5
- end
@@ -1,2 +0,0 @@
1
- # Name of the CMS Fiona Instance to access
2
- RailsConnector::Configuration.instance_name = 'default'
@@ -1,2 +0,0 @@
1
- # Put your local configuration here.
2
- # Don't forget to configure your SCM to ignore this file.
@@ -1,247 +0,0 @@
1
- require "helpful_configuration"
2
- require 'rails_connector/cms_base_model' if RailsConnector.platform_fiona?
3
- require "rails_connector/blob"
4
-
5
- module RailsConnector
6
-
7
- # @api public
8
- class Configuration
9
- # @api public
10
- DEFAULT_MODE = :live
11
-
12
- # Default fields which the {DefaultUserController} will store in the session.
13
- DEFAULT_STORE_USER_ATTRS_IN_SESSION = [:login, :first_name, :last_name, :email, :id]
14
-
15
- #
16
- # Default path of a CA certification file in PEM format.
17
- #
18
- # @api public
19
- DEFAULT_CA_FILE = File.expand_path('../../../config/ca-bundle.crt', __FILE__)
20
-
21
- class << self
22
-
23
- # there are three available modes for the rails connector:
24
- # <tt>live</tt> (show released contents only),
25
- # <tt>preview</tt> (show edited contents)
26
- # <tt>editor</tt> (show edited contents and editor interface (e.g. edit markers))
27
- # Default mode is <tt>live</tt>.
28
- # @api public
29
- attr_accessor :mode
30
-
31
- # default options for {SearchRequest}
32
- attr_writer :search_options
33
-
34
- # define a non-default blob cache dir.
35
- # +fiona connector+ only. has no effect when used with the +cloud connector+.
36
- # @api public
37
- attr_accessor :blob_cache_dir
38
-
39
- # Configuration for Content Read Service API.
40
- # @api public
41
- attr_reader :content_service
42
-
43
- # Determine if current visitor is permitted to edit content.
44
- attr_accessor :editing_auth_callback
45
-
46
- # Configure a callback to be invoked when the rails connector determines,
47
- # if current visitor is permitted to edit content.
48
- # Default is <code>false</code>.
49
- #
50
- # Example Usage:
51
- # RailsConnector::Configuation.editing_auth do |env|
52
- # request = Rack::Request.new(env)
53
- # # return truey if current visitor is permitted to edit content, falsy otherwise
54
- # end
55
- # @api public
56
- def editing_auth(&block)
57
- if block.respond_to?(:arity) && block.arity == 1
58
- self.editing_auth_callback = block
59
- else
60
- raise ArgumentError, 'editing_auth should have only one attribute!'
61
- end
62
- end
63
-
64
- # Gets path of a CA certification file in PEM format.
65
- # @api public
66
- attr_reader :ca_file
67
-
68
- # Sets path of a CA certification file in PEM format.
69
- # The file can contain several CA certificates.
70
- # Certifications will be used for endpoint peer verification of various Infopark services
71
- # e.g. Content Read Service.
72
- # @api public
73
- def ca_file=(path)
74
- File.read(path) if path # Try to read the given file and fail if it doesn't exist or is not readable.
75
- @ca_file = path
76
- end
77
-
78
- # default options for {SearchRequest}
79
- def search_options
80
- @search_options || local_config_file["search"].symbolize_keys
81
- end
82
-
83
- # @api public
84
- def mode=(new_mode)
85
- new_mode = new_mode.to_sym
86
- raise ArgumentError, "Unknown Mode #{new_mode}" unless [:editor, :preview, :live].include?(new_mode)
87
- @mode = new_mode
88
- end
89
-
90
- # there are three available modes for the rails connector:
91
- # <tt>live</tt> (show released contents only),
92
- # <tt>preview</tt> (show edited contents)
93
- # <tt>editor</tt> (show edited contents and editor interface (e.g. edit markers))
94
- # Default mode is <tt>live</tt>.
95
- # @api public
96
- def mode
97
- @mode || DEFAULT_MODE
98
- end
99
-
100
- #
101
- # Sets the array of fields which the +DefaultUserController+ will store in the session.
102
- # Defaults to {DEFAULT_STORE_USER_ATTRS_IN_SESSION}.
103
- #
104
- attr_writer :store_user_attrs_in_session
105
-
106
- #
107
- # Returns fields which the {DefaultUserController} stores in the session.
108
- # Defaults to {DEFAULT_STORE_USER_ATTRS_IN_SESSION}.
109
- #
110
- def store_user_attrs_in_session
111
- @store_user_attrs_in_session || DEFAULT_STORE_USER_ATTRS_IN_SESSION
112
- end
113
-
114
- def editor_interface_enabled?
115
- mode == :editor
116
- end
117
-
118
- def use_edited_content?
119
- mode == :preview || mode == :editor
120
- end
121
-
122
- # Configures your CMS instance name.
123
- #
124
- # Example call as to be used in <tt>rails_connector.rb</tt>:
125
- # RailsConnector::Configuration.instance_name = 'internet'
126
- # @api public
127
- def instance_name=(name)
128
- RailsConnector::CmsBaseModel.instance_name = name if RailsConnector.platform_fiona?
129
- end
130
-
131
- def after_initialize
132
- enable_ses
133
- enable_authentication
134
- ::RailsConnector::BasicObj.configure_for_content(
135
- ::RailsConnector::Configuration.use_edited_content? ? :edited : :released
136
- )
137
- end
138
-
139
- def to_prepare
140
- unless Rails.configuration.cache_classes
141
- after_initialize
142
- NamedLink.reset_cache
143
- BasicObj.reset_type_cache
144
- ::ApplicationController.__send__(:helper, :cms)
145
- end
146
- end
147
-
148
- def configure_cms_database
149
- if RailsConnector.platform_fiona?
150
- RailsConnector::CmsBaseModel.configure_database("cms")
151
- elsif local_config_file.configured?('content_service')
152
- @content_service = local_config_file['content_service']
153
- RailsConnector::CmsRestApi.credentials = local_config_file["cms_api"].symbolize_keys
154
- end
155
- end
156
-
157
- attr_accessor :choose_homepage_callback
158
-
159
- # Configure a callback to be invoked when the rails connector delivers the homepage.
160
- # The given callback will receive the rack env
161
- # and must return an Obj to be used as the homepage.
162
- # If no callback is configured, Obj.homepage will be used as the default.
163
- # @api public
164
- def choose_homepage(&block)
165
- self.choose_homepage_callback = block
166
- end
167
-
168
- def cms_routes(*args)
169
- raise <<-EOS.gsub(/\s+/, ' ')
170
- Calling RailsConnector::Configuration.cms_routes is not needed anymore.
171
- Please remove it from config/routes.rb
172
- EOS
173
- end
174
-
175
- def use_x_sendfile=(value)
176
- raise 'Configuration.use_x_sendfile is now available as Rails configuration:'\
177
- ' config.action_dispatch.x_sendfile_header = "X-Sendfile"'
178
- end
179
-
180
- def local_config_file
181
- @local_config_file ||= read_local_config_file
182
- end
183
-
184
- def local_config_file_name
185
- (Rails.root + "config/rails_connector.yml").expand_path
186
- end
187
-
188
- # for test purposes only
189
- def reset_local_config_file_cache
190
- @local_config_file = nil
191
- end
192
-
193
- protected
194
-
195
- def read_local_config_file
196
- contents = YAML.load_file(local_config_file_name) if File.exists?(local_config_file_name)
197
- contents ||= {}
198
-
199
- config = HelpfulConfiguration.new(
200
- contents,
201
- local_config_file_name
202
- )
203
- config.explain(
204
- "cms_database",
205
- "a hash of options, including type, that specify the database configuration"
206
- )
207
- config.explain(
208
- "cms_blob_storage",
209
- "a hash of options, including type, that specify the cms blob storage configuration"
210
- )
211
- config.explain(
212
- "cms_dict_storage",
213
- "a hash of options, including type, that specify the cms dict storage configuration"
214
- )
215
- config.explain(
216
- "search",
217
- "a hash of options that specify access to the search server"
218
- )
219
- config.explain(
220
- "cms_api",
221
- "a hash of options that specify access to the cms api"
222
- )
223
- config.explain 'content_service', 'a hash of options that specify access to content service'
224
- config
225
- end
226
-
227
- def enable_authentication
228
- ::ApplicationController.__send__(:include, RailsConnector::Authenticable)
229
- end
230
-
231
- def enable_ses
232
- if RailsConnector.platform_fiona?
233
- require 'rails_connector/ses'
234
-
235
- RailsConnector::SES.enable
236
- end
237
- end
238
- end
239
-
240
- # defaults
241
- self.ca_file = DEFAULT_CA_FILE
242
- self.editing_auth{ |env| false }
243
- end
244
-
245
- class ConfigurationError < StandardError
246
- end
247
- end