Module: Scrivito

Defined in:
lib/scrivito_sdk.rb,
lib/scrivito/diff.rb,
lib/scrivito/link.rb,
lib/scrivito/user.rb,
lib/scrivito/cache.rb,
lib/scrivito/binary.rb,
lib/scrivito/errors.rb,
lib/scrivito/cms_env.rb,
lib/scrivito/gem_info.rb,
lib/scrivito/obj_data.rb,
lib/scrivito/revision.rb,
lib/scrivito/attribute.rb,
lib/scrivito/basic_obj.rb,
lib/scrivito/obj_class.rb,
lib/scrivito/text_link.rb,
lib/scrivito/workspace.rb,
lib/scrivito/comparison.rb,
lib/scrivito/membership.rb,
lib/scrivito/migrations.rb,
lib/scrivito/named_link.rb,
lib/scrivito/sdk_engine.rb,
lib/scrivito/widget_tag.rb,
lib/scrivito/cms_backend.rb,
lib/scrivito/cms_routing.rb,
lib/scrivito/deprecation.rb,
lib/scrivito/html_string.rb,
lib/scrivito/layout_tags.rb,
lib/scrivito/link_parser.rb,
lib/scrivito/basic_widget.rb,
lib/scrivito/client_error.rb,
lib/scrivito/cms_rest_api.rb,
lib/scrivito/modification.rb,
lib/scrivito/tag_renderer.rb,
lib/scrivito/test_request.rb,
lib/scrivito/access_denied.rb,
lib/scrivito/backend_error.rb,
lib/scrivito/client_config.rb,
lib/scrivito/cms_field_tag.rb,
lib/scrivito/configuration.rb,
lib/scrivito/content_state.rb,
lib/scrivito/model_library.rb,
lib/scrivito/network_error.rb,
lib/scrivito/type_computer.rb,
lib/scrivito/child_list_tag.rb,
lib/scrivito/cms_data_cache.rb,
lib/scrivito/date_attribute.rb,
lib/scrivito/log_subscriber.rb,
lib/scrivito/model_identity.rb,
lib/scrivito/obj_class_data.rb,
lib/scrivito/obj_collection.rb,
lib/scrivito/routing_helper.rb,
lib/scrivito/string_tagging.rb,
lib/scrivito/workspace_data.rb,
lib/scrivito/cache/chainable.rb,
lib/scrivito/cache/ram_store.rb,
lib/scrivito/content_service.rb,
lib/scrivito/editing_context.rb,
lib/scrivito/restriction_set.rb,
lib/scrivito/uploaded_binary.rb,
lib/scrivito/user_definition.rb,
lib/scrivito/cache/file_store.rb,
lib/scrivito/cache_middleware.rb,
lib/scrivito/class_collection.rb,
lib/scrivito/image_tag_helper.rb,
lib/scrivito/attribute_content.rb,
lib/scrivito/obj_params_parser.rb,
lib/scrivito/widget_collection.rb,
lib/scrivito/connection_manager.rb,
lib/scrivito/content_conversion.rb,
lib/scrivito/controller_actions.rb,
lib/scrivito/controller_runtime.rb,
lib/scrivito/obj_data_from_hash.rb,
lib/scrivito/obj_search_builder.rb,
lib/scrivito/communication_error.rb,
lib/scrivito/migrations/migrator.rb,
lib/scrivito/rate_limit_exceeded.rb,
lib/scrivito/attribute_collection.rb,
lib/scrivito/attribute_definition.rb,
lib/scrivito/attribute_serializer.rb,
lib/scrivito/migrations/migration.rb,
lib/scrivito/obj_class_collection.rb,
lib/scrivito/text_link_conversion.rb,
app/models/scrivito/content_widget.rb,
lib/scrivito/content_state_caching.rb,
lib/scrivito/content_state_visitor.rb,
lib/scrivito/membership_collection.rb,
lib/scrivito/obj_data_from_service.rb,
lib/scrivito/obj_search_enumerator.rb,
lib/scrivito/attribute_deserializer.rb,
lib/scrivito/editing_context_helper.rb,
lib/scrivito/migrations/cms_backend.rb,
lib/scrivito/cache_garbage_collector.rb,
lib/scrivito/cms_dispatch_controller.rb,
lib/scrivito/obj_create_params_parser.rb,
lib/scrivito/obj_update_params_parser.rb,
app/controllers/scrivito/ui_controller.rb,
lib/scrivito/migrations/workspace_lock.rb,
lib/scrivito/widget_garbage_collection.rb,
lib/scrivito/workspace/publish_checker.rb,
lib/scrivito/editing_context_middleware.rb,
lib/scrivito/migrations/migration_store.rb,
app/controllers/scrivito/objs_controller.rb,
lib/scrivito/workspace_data_from_service.rb,
app/controllers/scrivito/blobs_controller.rb,
app/controllers/scrivito/tasks_controller.rb,
app/controllers/scrivito/users_controller.rb,
lib/scrivito/workspace_data_from_rest_api.rb,
lib/scrivito/attribute_definition_migrator.rb,
lib/scrivito/cms_rest_api/widget_extractor.rb,
lib/generators/scrivito/page/page_generator.rb,
lib/scrivito/workspace_selection_middleware.rb,
lib/scrivito/attribute_definition_collection.rb,
app/controllers/scrivito/webservice_controller.rb,
app/controllers/scrivito/workspaces_controller.rb,
app/controllers/scrivito/default_cms_controller.rb,
lib/generators/scrivito/widget/widget_generator.rb,
lib/generators/scrivito/install/install_generator.rb,
lib/generators/scrivito/migration/migration_generator.rb,
lib/scrivito/cms_rest_api/legacy_attribute_serializer.rb

Defined Under Namespace

Modules: AttributeContent, RoutingHelper, TestRequest Classes: Attribute, AttributeCollection, AttributeDefinition, AttributeDefinitionCollection, BasicObj, BasicWidget, Binary, CacheGarbageCollector, ClassCollection, Configuration, Link, Membership, MembershipCollection, ModelLibrary, NamedLink, ObjClass, ObjClassCollection, ObjClassNotFound, ObjCollection, ObjSearchEnumerator, ResourceNotFound, ScrivitoError, User, UserDefinition, WidgetCollection, Workspace

Class Method Summary collapse

Class Method Details

.configure {|Configuration| ... } ⇒ Object

Configures the Scrivito SDK. The configuration keys tenant and api_key must be provided.

Examples:

Scrivito.configure do |config|
  config.tenant  = 'my-tenant-name'
  config.api_key = 'secret'
end

Yields:



17
18
19
# File 'lib/scrivito_sdk.rb', line 17

def self.configure
  yield Configuration
end

.modelsObject

Configures which models Scrivito assumes as pages and widgets.

In order to display a page class selection dialog and a widget class selection dialog, Scrivito needs to know which page models and widget models are available. That models can be defined in the Rails application itself or in 3rd-party gems.

Scrivito will automatically assume all the classes descending from BasicObj, whose class names are ending with Page are pages (e.g. MyPage, HomePage, BlogPostPage etc.). It will also automatically assume all the classes descending from BasicWidget, whose class names are ending with Widget are widgets (e.g. TextWidget, ImageWdidget etc.).

Scrivito will recursively scan for such models in all directories from Scrivito.models.paths, which is an array of strings. It by default includes the directory app/models of the Rails application. For example it will find following page and widget models:

app/models/my_page.rb

app/models/my_widget.rb

app/models/my_namespace/my_other_page.rb

app/models/my_namespace/my_other_widget.rb

app/models/my_namespace/my_other_namespace/my_other_special_page.rb

app/models/my_namespace/my_other_namespace/my_other_special_widget.rb

Also Scrivito.models.paths will include all directories ending with app/models of any available Rails engine, as long as that directory is included in the autoload paths of Rails (which is the default). For example it will find following page and widget models in an engine:

/../some_engine/app/models/my_page.rb

/../some_engine/app/models/my_widget.rb

/../some_engine/app/models/my_namespace/my_other_page.rb

/../some_engine/app/models/my_namespace/my_other_widget.rb

/../some_engine/app/models/my_namespace/my_other_namespace/my_other_special_page.rb

/../some_engine/app/models/my_namespace/my_other_namespace/my_other_special_widget.rb

You can add custom directories to scan for models and register single page and widget models with Scrivito.models.define (see examples below).

The loaded pages can be inspected with Scrivito.models.pages, which will return a ClassCollection containing all available pages. The loaded widgets can be inspected with Scrivito.models.widgets, which will return a ClassCollection containing all available widgets.

The scan results are cached. If Rails.application.config.cache_classes is false, then the cache will be cleared on every request. Otherwise the cache will be kept between the requests. You can clear the cache with Scrivito.models.clear_cache.

Examples:

Register a custom path

Scrivito.models.define do
  paths << Rails.root + 'lib/special_models'
end

Register pages and widgets with inconvenient names

Scrivito.models.define do
  page 'MyCrazyPageModel'
  page 'MyOtherCrazyPageModel1', 'MyOtherCrazyPageModel2'

  widget 'MyCrazyWidgetModel'
  widget 'MyOtherCrazyWidgetModel1', 'MyOtherCrazyWidgetModel2'
end

Iterate over available pages

Scrivito.models.pages.each do |page_class|
  puts page_class.name
end
#=> "MyPage"
#=> "MyOtherPage"
# ...

Iterate over available widgets

Scrivito.models.widgets.each do |widget_class|
  puts widget_class.name
end
#=> "MyWidget"
#=> "MyOtherWidget"
# ...


111
112
113
# File 'lib/scrivito_sdk.rb', line 111

def self.models
  @models ||= ModelLibrary.new
end