Module: Alchemy

Defined in:
app/models/alchemy/tag.rb,
app/models/alchemy/node.rb,
app/models/alchemy/page.rb,
app/models/alchemy/site.rb,
app/models/alchemy/content.rb,
app/models/alchemy/element.rb,
app/models/alchemy/message.rb,
app/models/alchemy/picture.rb,
app/models/alchemy/language.rb,
app/models/alchemy/attachment.rb,
app/helpers/alchemy/url_helper.rb,
app/models/alchemy/base_record.rb,
app/models/alchemy/folded_page.rb,
app/models/alchemy/picture/url.rb,
app/models/alchemy/site/layout.rb,
app/helpers/alchemy/base_helper.rb,
app/mailers/alchemy/base_mailer.rb,
app/models/alchemy/essence_date.rb,
app/models/alchemy/essence_file.rb,
app/models/alchemy/essence_html.rb,
app/models/alchemy/essence_link.rb,
app/models/alchemy/essence_node.rb,
app/models/alchemy/essence_page.rb,
app/models/alchemy/essence_text.rb,
app/helpers/alchemy/pages_helper.rb,
app/models/alchemy/page/url_path.rb,
app/models/alchemy/picture_thumb.rb,
app/models/alchemy/attachment/url.rb,
app/models/alchemy/essence_select.rb,
app/models/alchemy/content/factory.rb,
app/models/alchemy/element_to_page.rb,
app/models/alchemy/essence_boolean.rb,
app/models/alchemy/essence_picture.rb,
app/models/alchemy/picture_variant.rb,
app/helpers/alchemy/elements_helper.rb,
app/mailers/alchemy/messages_mailer.rb,
app/models/alchemy/essence_richtext.rb,
app/models/alchemy/page/page_naming.rb,
app/models/alchemy/page/page_scopes.rb,
app/models/alchemy/page/page_natures.rb,
app/models/alchemy/picture_thumb/uid.rb,
app/decorators/alchemy/content_editor.rb,
app/decorators/alchemy/element_editor.rb,
app/helpers/alchemy/admin/base_helper.rb,
app/helpers/alchemy/admin/form_helper.rb,
app/helpers/alchemy/admin/tags_helper.rb,
app/models/alchemy/element/presenters.rb,
app/models/alchemy/page/page_elements.rb,
app/helpers/alchemy/admin/pages_helper.rb,
app/models/alchemy/element/definitions.rb,
app/controllers/alchemy/base_controller.rb,
app/models/alchemy/essence_picture_view.rb,
app/models/alchemy/picture/calculations.rb,
app/models/alchemy/picture/preprocessor.rb,
app/models/alchemy/picture_thumb/create.rb,
app/serializers/alchemy/base_serializer.rb,
app/serializers/alchemy/node_serializer.rb,
app/serializers/alchemy/page_serializer.rb,
app/controllers/alchemy/pages_controller.rb,
app/models/alchemy/page/fixed_attributes.rb,
app/helpers/alchemy/admin/contents_helper.rb,
app/helpers/alchemy/admin/elements_helper.rb,
app/helpers/alchemy/admin/essences_helper.rb,
app/helpers/alchemy/admin/pictures_helper.rb,
app/helpers/alchemy/elements_block_helper.rb,
app/models/alchemy/picture/transformations.rb,
app/models/alchemy/picture_thumb/signature.rb,
app/models/concerns/alchemy/touch_elements.rb,
app/serializers/alchemy/content_serializer.rb,
app/serializers/alchemy/element_serializer.rb,
app/serializers/alchemy/picture_serializer.rb,
app/controllers/alchemy/api/base_controller.rb,
app/controllers/alchemy/elements_controller.rb,
app/controllers/alchemy/messages_controller.rb,
app/helpers/alchemy/admin/navigation_helper.rb,
app/models/alchemy/element/element_contents.rb,
app/models/alchemy/element/element_essences.rb,
app/controllers/alchemy/api/nodes_controller.rb,
app/controllers/alchemy/api/pages_controller.rb,
app/helpers/alchemy/admin/attachments_helper.rb,
app/serializers/alchemy/page_tree_serializer.rb,
app/controllers/alchemy/admin/base_controller.rb,
app/controllers/alchemy/admin/tags_controller.rb,
app/serializers/alchemy/attachment_serializer.rb,
app/controllers/alchemy/admin/nodes_controller.rb,
app/controllers/alchemy/admin/pages_controller.rb,
app/controllers/alchemy/admin/sites_controller.rb,
app/controllers/alchemy/admin/trash_controller.rb,
app/controllers/alchemy/attachments_controller.rb,
app/controllers/alchemy/api/contents_controller.rb,
app/controllers/alchemy/api/elements_controller.rb,
app/controllers/concerns/alchemy/site_redirects.rb,
app/serializers/alchemy/essence_date_serializer.rb,
app/serializers/alchemy/essence_file_serializer.rb,
app/serializers/alchemy/essence_html_serializer.rb,
app/serializers/alchemy/essence_link_serializer.rb,
app/serializers/alchemy/essence_text_serializer.rb,
app/controllers/alchemy/admin/contents_controller.rb,
app/controllers/alchemy/admin/elements_controller.rb,
app/controllers/alchemy/admin/pictures_controller.rb,
app/serializers/alchemy/essence_select_serializer.rb,
app/controllers/alchemy/admin/clipboard_controller.rb,
app/controllers/alchemy/admin/dashboard_controller.rb,
app/controllers/alchemy/admin/languages_controller.rb,
app/controllers/alchemy/admin/resources_controller.rb,
app/serializers/alchemy/essence_boolean_serializer.rb,
app/serializers/alchemy/essence_picture_serializer.rb,
app/controllers/alchemy/admin/styleguide_controller.rb,
app/serializers/alchemy/essence_richtext_serializer.rb,
app/controllers/alchemy/admin/attachments_controller.rb,
app/controllers/alchemy/admin/layoutpages_controller.rb,
app/controllers/alchemy/admin/essence_files_controller.rb,
app/controllers/concerns/alchemy/admin/archive_overlay.rb,
app/controllers/concerns/alchemy/legacy_page_redirects.rb,
app/controllers/concerns/alchemy/admin/current_language.rb,
app/controllers/alchemy/admin/essence_pictures_controller.rb,
app/controllers/alchemy/admin/legacy_page_urls_controller.rb,
app/controllers/concerns/alchemy/admin/uploader_responses.rb,
lib/alchemy_cms.rb,
lib/alchemy/i18n.rb,
lib/alchemy/hints.rb,
lib/alchemy/paths.rb,
lib/alchemy/shell.rb,
lib/alchemy/config.rb,
lib/alchemy/engine.rb,
lib/alchemy/errors.rb,
lib/alchemy/logger.rb,
lib/alchemy/seeder.rb,
lib/alchemy/essence.rb,
lib/alchemy/modules.rb,
lib/alchemy/tinymce.rb,
lib/alchemy/version.rb,
lib/alchemy/resource.rb,
lib/alchemy/taggable.rb,
lib/alchemy/upgrader.rb,
lib/alchemy/filetypes.rb,
lib/alchemy/tasks/tidy.rb,
lib/alchemy/deprecation.rb,
lib/alchemy/page_layout.rb,
lib/alchemy/permissions.rb,
lib/alchemy/admin/locale.rb,
lib/alchemy/forms/builder.rb,
lib/alchemy/install/tasks.rb,
lib/alchemy/auth_accessors.rb,
lib/alchemy/on_page_layout.rb,
lib/alchemy/elements_finder.rb,
lib/generators/alchemy/base.rb,
lib/alchemy/name_conversions.rb,
lib/alchemy/resources_helper.rb,
lib/alchemy/admin/preview_url.rb,
lib/alchemy/controller_actions.rb,
lib/alchemy/routing_constraints.rb,
lib/alchemy/configuration_methods.rb,
lib/alchemy/upgrader/five_point_zero.rb,
lib/alchemy/test_support/config_stubbing.rb,
lib/alchemy/cache_digests/template_tracker.rb,
lib/alchemy/on_page_layout/callbacks_runner.rb,
lib/alchemy/test_support/integration_helpers.rb,
lib/generators/alchemy/menus/menus_generator.rb,
lib/generators/alchemy/views/views_generator.rb,
lib/generators/alchemy/module/module_generator.rb,
lib/generators/alchemy/essence/essence_generator.rb,
lib/generators/alchemy/install/install_generator.rb,
lib/generators/alchemy/elements/elements_generator.rb,
lib/generators/alchemy/page_layouts/page_layouts_generator.rb,
lib/generators/alchemy/site_layouts/site_layouts_generator.rb

Overview

Provides authentication accessors.

Alchemy has some defaults for user model name and login logout path names:

Alchemy.user_class_name defaults to 'User' Alchemy.user_class_primary_key defaults to :id Alchemy.current_user_method defaults to 'current_user'+ Alchemy.signup_path defaults to '/signup'+ Alchemy.login_path defaults to '/login'+ Alchemy.logout_path defaults to '/logout'+ Alchemy.logout_method defaults to 'delete'+

Anyway, you can tell Alchemy about your authentication model configuration:

1. Your user class name - @see: Alchemy.user_class
2. Your users table primary key - @see: Alchemy.user_class_primary_key
3. A method on your ApplicationController to get current user -
   @see: Alchemy.current_user_method
4. The path to the signup form - @see: Alchemy.signup_path
5. The path to the login form - @see: Alchemy.login_path
6. The path to the logout method - @see: Alchemy.logout_path
7. The http verb for the logout method - @see: Alchemy.logout_method

Example

# config/initializers/alchemy.rb
Alchemy.user_class_name = 'Admin'
Alchemy.user_class_primary_key = :user_id
Alchemy.current_user_method = 'current_admin'
Alchemy. = '/auth/signup'
Alchemy. = '/auth/login'
Alchemy.logout_path = '/auth/logout'
Alchemy.logout_method = 'get'

If you don't have your own user model or don't want to provide one, add the `alchemy-devise` gem into your App's Gemfile.

Adding your own CanCan abilities

If your app or your engine has own CanCan abilities you must register them:

Alchemy.register_ability MyCustom::Ability

Defined Under Namespace

Modules: AbilityHelper, Admin, BaseHelper, CacheDigests, ConfigurationMethods, ControllerActions, ElementsBlockHelper, ElementsHelper, Essence, Filetypes, Forms, Generators, Hints, I18n, Install, LegacyPageRedirects, Logger, Modules, NameConversions, OnPageLayout, PagesHelper, ResourcesHelper, Shell, SiteRedirects, Taggable, TestSupport, Tinymce, TouchElements, UrlHelper Classes: Attachment, AttachmentSerializer, AttachmentsController, BaseController, BaseMailer, BaseRecord, BaseSerializer, Config, Content, ContentDefinitionError, ContentEditor, ContentSerializer, DefaultLanguageNotFoundError, DefaultSiteNotFoundError, Element, ElementDefinitionError, ElementEditor, ElementSerializer, ElementToPage, ElementsController, ElementsFinder, Engine, EssenceBoolean, EssenceBooleanSerializer, EssenceDate, EssenceDateSerializer, EssenceFile, EssenceFileSerializer, EssenceHtml, EssenceHtmlSerializer, EssenceLink, EssenceLinkSerializer, EssenceMissingError, EssenceNode, EssencePage, EssencePicture, EssencePictureSerializer, EssencePictureView, EssenceRichtext, EssenceRichtextSerializer, EssenceSelect, EssenceSelectSerializer, EssenceText, EssenceTextSerializer, FoldedPage, IngredientAssociation, Language, LegacyPageUrl, Message, MessagesController, MessagesMailer, MissingActiveRecordAssociation, MissingImageFileError, NoCurrentUserFoundError, Node, NodeSerializer, NotMountedError, Page, PageLayout, PageSerializer, PageTreeSerializer, PagesController, Permissions, Picture, PictureInUseError, PictureSerializer, PictureThumb, PictureVariant, Resource, RoutingConstraints, Seeder, Site, Tag, Tidy, TinymceError, UpdateServiceUnavailable, Upgrader, WrongImageFormatError

Constant Summary collapse

YAML_WHITELIST_CLASSES =
%w(Symbol Date Regexp)
VERSION =
"5.1.0.alpha"
Deprecation =
ActiveSupport::Deprecation.new("5.1", "Alchemy")
@@admin_path =

Defaults

"admin"
@@admin_constraints =
{}
@@user_class_name =

Defaults

"User"
@@user_class_primary_key =
:id
@@current_user_method =
"current_user"
@@signup_path =
"/signup"
@@login_path =
"/login"
@@logout_path =
"/logout"
@@logout_method =
"delete"

Class Method Summary collapse

Class Method Details

.gem_versionObject


10
11
12
# File 'lib/alchemy/version.rb', line 10

def self.gem_version
  Gem::Version.new(VERSION)
end

.register_ability(klass) ⇒ Object

Register a CanCan Ability class


112
113
114
115
# File 'lib/alchemy/auth_accessors.rb', line 112

def self.register_ability(klass)
  @abilities ||= []
  @abilities << klass
end

.registered_abilitiesObject

All CanCan Ability classes registered to Alchemy


119
120
121
# File 'lib/alchemy/auth_accessors.rb', line 119

def self.registered_abilities
  @abilities ||= []
end

.t(msg, *args) ⇒ Object

Alchemy shortcut translation method

Instead of having to call:

Alchemy::I18n.translate(:hello)

You can use this shortcut method:

Alchemy.t(:hello)

15
16
17
# File 'lib/alchemy/i18n.rb', line 15

def t(msg, *args)
  Alchemy::I18n.translate(msg, *args)
end

.table_name_prefixObject


3
4
5
# File 'app/models/alchemy/base_record.rb', line 3

def self.table_name_prefix
  "alchemy_"
end

.user_classObject


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/alchemy/auth_accessors.rb', line 89

def self.user_class
  @@user_class ||= begin
    @@user_class_name.constantize
  rescue NameError => e
    if e.message =~ /#{Regexp.escape(@@user_class_name)}/
      abort <<-MSG.strip_heredoc

      AlchemyCMS cannot find any user class!

      Please add a user class and tell Alchemy about it or, if you don't want
      to create your own class, add the `alchemy-devise` gem to your Gemfile.

          bundle add alchemy-devise

      MSG
    else
      raise e
    end
  end
end

.user_class_nameObject

Prefix with

when getting to avoid constant name conflicts


77
78
79
80
81
82
83
# File 'lib/alchemy/auth_accessors.rb', line 77

def self.user_class_name
  if !@@user_class_name.is_a?(String)
    raise TypeError, "Alchemy.user_class_name must be a String, not a Class."
  end

  "::#{@@user_class_name}"
end

.user_class_name=(user_class_name) ⇒ Object


85
86
87
# File 'lib/alchemy/auth_accessors.rb', line 85

def self.user_class_name=(user_class_name)
  @@user_class_name = user_class_name
end

.versionObject


6
7
8
# File 'lib/alchemy/version.rb', line 6

def self.version
  VERSION
end