Module: Refinery

Defined in:
core/lib/refinery/crud.rb,
core/lib/refinery.rb,
core/lib/refinery/cli.rb,
core/lib/refinery/core.rb,
core/lib/refinery/menu.rb,
core/lib/refinery/engine.rb,
core/lib/refinery/errors.rb,
core/lib/refinery/plugin.rb,
core/lib/refinery/plugins.rb,
core/lib/refinery/version.rb,
core/lib/refinery/menu_item.rb,
core/lib/refinery/core/engine.rb,
core/lib/refinery/core/nil_user.rb,
core/lib/refinery/users_manager.rb,
core/spec/lib/refinery/crud_spec.rb,
core/spec/lib/refinery/crud_spec.rb,
core/spec/lib/refinery/menu_spec.rb,
core/spec/lib/refinery/plugin_spec.rb,
core/spec/lib/refinery/plugin_spec.rb,
core/spec/lib/refinery/plugins_spec.rb,
core/app/helpers/refinery/tag_helper.rb,
core/lib/refinery/core/configuration.rb,
core/lib/refinery/core/default_route.rb,
core/app/helpers/refinery/menu_helper.rb,
core/app/helpers/refinery/meta_helper.rb,
core/spec/features/refinery/core_spec.rb,
core/app/helpers/refinery/admin_helper.rb,
core/app/helpers/refinery/image_helper.rb,
core/lib/refinery/extension_generation.rb,
core/lib/refinery/admin/base_controller.rb,
core/lib/refinery/generators/named_base.rb,
core/spec/support/fixtures/valid_engine.rb,
core/app/models/refinery/core/base_model.rb,
core/lib/refinery/application_controller.rb,
core/app/helpers/refinery/site_bar_helper.rb,
core/spec/features/refinery/site_bar_spec.rb,
core/spec/lib/refinery/core/nil_user_spec.rb,
core/spec/lib/refinery/users_manager_spec.rb,
core/spec/support/fixtures/invalid_engine.rb,
core/spec/helpers/refinery/tag_helper_spec.rb,
core/app/helpers/refinery/pagination_helper.rb,
core/app/presenters/refinery/base_presenter.rb,
core/spec/helpers/refinery/meta_helper_spec.rb,
core/app/helpers/refinery/translation_helper.rb,
core/lib/refinery/core/authorisation_adapter.rb,
core/lib/refinery/core/authorisation_manager.rb,
core/spec/helpers/refinery/admin_helper_spec.rb,
core/app/controllers/refinery/fast_controller.rb,
core/app/controllers/refinery/admin_controller.rb,
core/app/helpers/refinery/custom_assets_helper.rb,
core/lib/generators/refinery/cms/cms_generator.rb,
core/spec/features/refinery/admin/dialogs_spec.rb,
core/spec/lib/refinery/core/configuration_spec.rb,
core/app/controllers/refinery/sitemap_controller.rb,
core/app/helpers/refinery/html_truncation_helper.rb,
core/lib/generators/refinery/core/core_generator.rb,
core/lib/refinery/generators/generated_attribute.rb,
core/spec/features/refinery/admin/xhr_paging_spec.rb,
core/spec/helpers/refinery/pagination_helper_spec.rb,
core/spec/lib/refinery/authorisation_manager_spec.rb,
core/lib/generators/refinery/dummy/dummy_generator.rb,
core/spec/helpers/refinery/translation_helper_spec.rb,
core/spec/lib/refinery/application_controller_spec.rb,
core/app/controllers/refinery/admin/core_controller.rb,
core/spec/features/refinery/application_layout_spec.rb,
core/app/helpers/refinery/admin/visual_editor_helper.rb,
core/lib/generators/refinery/engine/engine_generator.rb,
core/spec/features/refinery/admin/custom_assets_spec.rb,
core/spec/helpers/refinery/custom_assets_helper_spec.rb,
core/app/controllers/refinery/admin/dialogs_controller.rb,
core/spec/controllers/refinery/sitemap_controller_spec.rb,
core/spec/helpers/refinery/html_truncation_helper_spec.rb,
core/app/presenters/refinery/translated_field_presenter.rb,
core/spec/lib/generators/refinery/cms/cms_generator_spec.rb,
core/spec/controllers/refinery/admin/dummy_controller_spec.rb,
core/spec/controllers/refinery/admin/dummy_controller_spec.rb,
core/spec/lib/generators/refinery/core/core_generator_spec.rb,
core/spec/presenters/refinery/translated_field_presenter_spec.rb,
core/spec/lib/generators/refinery/engine/engine_generator_spec.rb,
core/spec/lib/generators/refinery/engine/engine_generator_with_i18n_spec.rb,
core/spec/lib/generators/refinery/engine/engine_generator_with_author_spec.rb,
core/spec/lib/generators/refinery/engine/engine_generator_sanity_check_spec.rb,
core/spec/lib/generators/refinery/engine/engine_generator_without_frontend_spec.rb,
core/spec/lib/generators/refinery/engine/engine_generator_multiple_resources_spec.rb,
images/lib/refinery/images.rb,
images/app/models/refinery/image.rb,
images/lib/refinery/images/engine.rb,
images/lib/refinery/images/dragonfly.rb,
images/lib/refinery/images/validators.rb,
images/spec/models/refinery/image_spec.rb,
images/lib/refinery/images/configuration.rb,
images/spec/lib/refinery/images/dragonfly_spec.rb,
images/app/helpers/refinery/admin/images_helper.rb,
images/app/models/refinery/thumbnail_dimensions.rb,
images/spec/features/refinery/admin/images_spec.rb,
images/spec/models/refinery/thumbnail_dimensions_spec.rb,
images/lib/generators/refinery/images/images_generator.rb,
images/app/controllers/refinery/admin/images_controller.rb,
images/lib/refinery/images/validators/image_size_validator.rb,
images/lib/refinery/images/validators/image_update_validator.rb,
images/spec/lib/generators/refinery/images/images_generator_spec.rb,
pages/lib/refinery/pages.rb,
pages/spec/lib/pages_spec.rb,
pages/lib/refinery/pages/tab.rb,
pages/lib/refinery/pages/url.rb,
pages/lib/refinery/pages/type.rb,
pages/app/models/refinery/page.rb,
pages/lib/refinery/pages/types.rb,
pages/lib/refinery/pages/engine.rb,
pages/lib/refinery/pages/finder.rb,
pages/app/models/refinery/page_part.rb,
pages/spec/models/refinery/page_spec.rb,
pages/lib/refinery/pages/configuration.rb,
pages/spec/lib/refinery/pages/tab_spec.rb,
pages/spec/lib/refinery/pages/url_spec.rb,
pages/lib/refinery/pages/render_options.rb,
pages/spec/features/refinery/pages_spec.rb,
pages/spec/models/refinery/page_url_spec.rb,
pages/lib/refinery/pages/instance_methods.rb,
pages/spec/models/refinery/page_menu_spec.rb,
pages/spec/models/refinery/page_part_spec.rb,
pages/spec/models/refinery/page_finder_spec.rb,
pages/app/presenters/refinery/page_presenter.rb,
pages/app/helpers/refinery/admin/pages_helper.rb,
pages/spec/features/refinery/admin/pages_spec.rb,
pages/spec/models/refinery/page_meta_data_spec.rb,
pages/app/controllers/refinery/pages_controller.rb,
pages/lib/refinery/pages/admin/instance_methods.rb,
pages/app/presenters/refinery/pages/menu_presenter.rb,
pages/lib/generators/refinery/pages/pages_generator.rb,
pages/app/controllers/refinery/admin/pages_controller.rb,
pages/app/helpers/refinery/pages/content_pages_helper.rb,
pages/app/presenters/refinery/pages/content_presenter.rb,
pages/app/presenters/refinery/pages/section_presenter.rb,
pages/spec/controllers/refinery/pages_controller_spec.rb,
pages/spec/presenters/refinery/pages/menu_presenter_spec.rb,
pages/spec/helpers/refinery/pages/admin/pages_helper_spec.rb,
pages/app/controllers/refinery/admin/page_parts_controller.rb,
pages/app/presenters/refinery/pages/content_page_presenter.rb,
pages/app/presenters/refinery/pages/title_section_presenter.rb,
pages/spec/controllers/refinery/admin/pages_controller_spec.rb,
pages/spec/helpers/refinery/pages/content_pages_helper_spec.rb,
pages/spec/presenters/refinery/pages/content_presenter_spec.rb,
pages/spec/presenters/refinery/pages/section_presenter_spec.rb,
pages/app/controllers/refinery/admin/pages_dialogs_controller.rb,
pages/app/controllers/refinery/pages/admin/preview_controller.rb,
pages/spec/lib/generators/refinery/pages/pages_generator_spec.rb,
pages/app/presenters/refinery/pages/page_part_section_presenter.rb,
pages/spec/presenters/refinery/pages/content_page_presenter_spec.rb,
pages/spec/presenters/refinery/pages/title_section_presenter_spec.rb,
pages/spec/presenters/refinery/pages/page_part_section_presenter_spec.rb,
resources/lib/refinery/resources.rb,
resources/app/models/refinery/resource.rb,
resources/lib/refinery/resources/engine.rb,
resources/lib/refinery/resources/dragonfly.rb,
resources/lib/refinery/resources/validators.rb,
resources/spec/models/refinery/resource_spec.rb,
resources/lib/refinery/resources/configuration.rb,
resources/spec/features/refinery/admin/resources_spec.rb,
resources/app/controllers/refinery/admin/resources_controller.rb,
resources/lib/generators/refinery/resources/resources_generator.rb,
resources/lib/refinery/resources/validators/file_size_validator.rb,
resources/spec/lib/generators/refinery/resources/resources_generator_spec.rb

Overview

Filters added to this controller apply to all controllers in the refinery backend. Likewise, all the methods added will be available for all controllers in the refinery backend.

Defined Under Namespace

Modules: Admin, AdminHelper, ApplicationController, Core, Crud, CustomAssetsHelper, Engine, ExtensionGeneration, Generators, HtmlTruncationHelper, ImageHelper, Images, InvalidEngine, MenuHelper, MetaHelper, MyOtherPlugin, MyPlugin, Pages, PaginationHelper, RefineryRspec, Resources, SiteBarHelper, TagHelper, TranslationHelper, ValidEngine Classes: AdminController, BasePresenter, CLI, CmsGenerator, CoreGenerator, CrudDummy, CrudDummyController, DummyGenerator, EngineGenerator, FastController, Image, ImagesGenerator, InvalidEngineError, Menu, MenuItem, Page, PagePart, PagePresenter, PagesController, PagesGenerator, Plugin, Plugins, RefineryError, Resource, ResourcesGenerator, SitemapController, ThumbnailDimensions, TranslatedFieldPresenter, Version

Constant Summary

@@extensions =
[]

Class Method Summary collapse

Class Method Details

.deprecate(what, options = {}) ⇒ Object

Constructs a deprecation warning message and warns with Kernel#warn

Example:

Refinery.deprecate('foo') => "The use of 'foo' is deprecated"

An options parameter can be specified to construct a more detailed deprecation message

Options:

when - version that this deprecated feature will be removed
replacement - a replacement for what is being deprecated
caller - who called the deprecated feature

Example:

Refinery.deprecate('foo', :when => 'tomorrow', :replacement => 'bar') =>
    "The use of 'foo' is deprecated and will be removed at version 2.0. Please use 'bar' instead."


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'core/lib/refinery.rb', line 85

def deprecate(what, options = {})
  # Build a warning.
  warning = "\n-- DEPRECATION WARNING --\nThe use of '#{what}' is deprecated"
  warning << " and will be removed at version #{options[:when]}" if options[:when]
  warning << "."
  warning << "\nPlease use #{options[:replacement]} instead." if options[:replacement]

  # See if we can trace where this happened
  if (invoker = detect_invoker(options[:caller])).present?
    warning << invoker
  end

  # Give stern talking to.
  warn warning
end

.extension_registered?(const) ⇒ Boolean

Returns true if an extension is currently registered with Refinery

Example:

Refinery.extension_registered?(Refinery::Core)

Returns:

  • (Boolean)


66
67
68
# File 'core/lib/refinery.rb', line 66

def extension_registered?(const)
  @@extensions.include?(const)
end

.extensionsObject

Returns an array of modules representing currently registered Refinery Engines

Example:

Refinery.extensions  =>  [Refinery::Core, Refinery::Pages]


37
38
39
# File 'core/lib/refinery.rb', line 37

def extensions
  @@extensions
end

.include_once(base, extension_module) ⇒ Object



164
165
166
# File 'core/lib/refinery.rb', line 164

def include_once(base, extension_module)
  base.send :include, extension_module unless included_extension_module?(base, extension_module)
end

.register_extension(const) ⇒ Object Also known as: register_engine

Register an extension with Refinery

Example:

Refinery.register_extension(Refinery::Core)


45
46
47
48
49
50
51
# File 'core/lib/refinery.rb', line 45

def register_extension(const)
  return if extension_registered?(const)

  validate_extension!(const)

  @@extensions << const
end

.rootObject

Returns a Pathname to the root of the Refinery CMS project



102
103
104
# File 'core/lib/refinery.rb', line 102

def root
  @root ||= Pathname.new(File.expand_path('../../../', __FILE__))
end

.roots(extension_name = nil) ⇒ Object

Returns an array of Pathnames pointing to the root directory of each extension that has been registered with Refinery.

Example:

Refinery.roots => [#<Pathname:/Users/Reset/Code/refinerycms/core>, #<Pathname:/Users/Reset/Code/refinerycms/pages>]

An optional extension_name parameter can be specified to return just the Pathname for the specified extension. This can be represented in Constant, Symbol, or String form.

Example:

Refinery.roots(Refinery::Core)    =>  #<Pathname:/Users/Reset/Code/refinerycms/core>
Refinery.roots(:'refinery/core')  =>  #<Pathname:/Users/Reset/Code/refinerycms/core>
Refinery.roots("refinery/core")   =>  #<Pathname:/Users/Reset/Code/refinerycms/core>


119
120
121
122
123
# File 'core/lib/refinery.rb', line 119

def roots(extension_name = nil)
  return @roots ||= self.extensions.map(&:root) if extension_name.nil?

  extension_name.to_s.camelize.constantize.root
end

.route_for_model(klass, options = {}) ⇒ Object

Returns string version of url helper path. We need this to temporarily support namespaces like Refinery::Image and Refinery::Blog::Post

Example:

Refinery.route_for_model(Refinery::Image) => "admin_image_path"
Refinery.route_for_model(Refinery::Image, {:plural => true}) => "admin_images_path"
Refinery.route_for_model(Refinery::Blog::Post) => "blog_admin_post_path"
Refinery.route_for_model(Refinery::Blog::Post, {:plural => true}) => "blog_admin_posts_path"
Refinery.route_for_model(Refinery::Blog::Post, {:admin => false}) => "blog_post_path"


138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'core/lib/refinery.rb', line 138

def route_for_model(klass, options = {})
  options = {:plural => false, :admin => true}.merge options

  klass = klass.constantize if klass.respond_to?(:constantize)
  active_name = ::ActiveModel::Name.new(
    klass, (Refinery if klass.parents.include?(Refinery))
  )

  if options[:admin]
    # Most of the time this gets rid of 'refinery'
    parts = active_name.to_s.underscore.split('/').reject do |name|
      active_name.singular_route_key.exclude?(name)
    end

    # Get the singular resource_name from the url parts
    resource_name = parts.pop
    resource_name = resource_name.pluralize if options[:plural]

    [parts.join("_"), "admin", resource_name, "path"].reject(&:blank?).join "_"
  else
    path = options[:plural] ? active_name.route_key : active_name.singular_route_key

    [path, 'path'].join '_'
  end
end

.unregister_extension(const) ⇒ Object

Unregister an extension from Refinery

Example:

Refinery.unregister_extension(Refinery::Core)


58
59
60
# File 'core/lib/refinery.rb', line 58

def unregister_extension(const)
  @@extensions.delete(const)
end

.versionObject



125
126
127
# File 'core/lib/refinery.rb', line 125

def version
  Refinery::Version.to_s
end