Module: Refinery

Defined in:
lib/refinery/crud.rb,
lib/refinery/cli.rb,
lib/refinery/core.rb,
lib/refinery/menu.rb,
lib/refinery/engine.rb,
lib/refinery/errors.rb,
lib/refinery/plugin.rb,
lib/refinery/plugins.rb,
lib/refinery/version.rb,
lib/refinery/activity.rb,
lib/refinery/menu_item.rb,
lib/refinery/core/engine.rb,
lib/refinery/base_presenter.rb,
app/helpers/refinery/tag_helper.rb,
lib/refinery/core/configuration.rb,
app/helpers/refinery/menu_helper.rb,
app/helpers/refinery/meta_helper.rb,
app/helpers/refinery/image_helper.rb,
lib/refinery/extension_generation.rb,
lib/refinery/admin/base_controller.rb,
app/models/refinery/core/base_model.rb,
lib/refinery/application_controller.rb,
app/helpers/refinery/site_bar_helper.rb,
app/helpers/refinery/pagination_helper.rb,
app/helpers/refinery/translation_helper.rb,
app/controllers/refinery/fast_controller.rb,
app/controllers/refinery/admin_controller.rb,
app/helpers/refinery/custom_assets_helper.rb,
lib/generators/refinery/cms/cms_generator.rb,
app/controllers/refinery/sitemap_controller.rb,
app/helpers/refinery/html_truncation_helper.rb,
lib/generators/refinery/core/core_generator.rb,
lib/generators/refinery/form/form_generator.rb,
lib/generators/refinery/dummy/dummy_generator.rb,
lib/generators/refinery/engine/engine_generator.rb,
app/controllers/refinery/admin/dialogs_controller.rb,
app/controllers/refinery/admin/refinery_core_controller.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, ApplicationController, Core, Crud, CustomAssetsHelper, Engine, Engines, ExtensionGeneration, HtmlTruncationHelper, ImageHelper, MenuHelper, MetaHelper, PaginationHelper, SiteBarHelper, TagHelper, TranslationHelper Classes: Activity, AdminController, BasePresenter, CLI, CmsGenerator, CoreGenerator, DummyGenerator, EngineGenerator, FastController, FormGenerator, InvalidEngineError, Menu, MenuItem, Plugin, Plugins, RefineryError, SitemapController, Version

Constant Summary collapse

WINDOWS =
!!(RbConfig::CONFIG['host_os'] =~ %r!(msdos|mswin|djgpp|mingw)!) unless
@@extensions =
[]

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

Returns the value of attribute menus.



5
6
7
# File 'lib/refinery/menu.rb', line 5

def menus
  @menus
end

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."


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/refinery/core.rb', line 91

def deprecate(what, options = {})
  # Build a warning.
  warning = "\n-- DEPRECATION WARNING --\n"
  warning << "The 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 options[:caller]
    whos_calling = options[:caller].detect{|c| c =~ %r{#{Rails.root.to_s}}}.inspect.to_s.split(':in').first
    warning << "\nCalled from: #{whos_calling}\n"
  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)


72
73
74
# File 'lib/refinery/core.rb', line 72

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]


43
44
45
# File 'lib/refinery/core.rb', line 43

def extensions
  @@extensions
end

.i18n_enabled?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/refinery/core.rb', line 109

def i18n_enabled?
  !!(defined?(::Refinery::I18n) && ::Refinery::I18n.enabled?)
end

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

Register an extension with Refinery

Example:

Refinery.register_extension(Refinery::Core)


51
52
53
54
55
56
57
# File 'lib/refinery/core.rb', line 51

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



114
115
116
# File 'lib/refinery/core.rb', line 114

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>


131
132
133
134
135
# File 'lib/refinery/core.rb', line 131

def roots(extension_name = nil)
  return @roots ||= self.extensions.map { |extension| extension.root } if extension_name.nil?

  extension_name.to_s.camelize.constantize.root
end

.route_for_model(klass, plural = false) ⇒ Object

Returns string version of url helper path. We need this to temporary 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, true) => "admin_images_path"
Refinery.route_for_model(Refinery::Blog::Post) => "blog_admin_post_path"
Refinery.route_for_model(Refinery::Blog::Post, true) => "blog_admin_posts_path"


149
150
151
152
153
154
155
156
157
158
159
# File 'lib/refinery/core.rb', line 149

def route_for_model(klass, plural = false)
  parts = klass.to_s.underscore.split('/').delete_if { |p| p.blank? }

  resource_name = plural ? parts[-1].pluralize : parts[-1]

  if parts.size == 2
    "admin_#{resource_name}_path"
  elsif parts.size > 2
    [parts[1..-2].join("_"), "admin", resource_name, "path"].join("_")
  end
end

.unregister_extension(const) ⇒ Object

Unregister an extension from Refinery

Example:

Refinery.unregister_extension(Refinery::Core)


64
65
66
# File 'lib/refinery/core.rb', line 64

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

.versionObject



137
138
139
# File 'lib/refinery/core.rb', line 137

def version
  Refinery::Version.to_s
end