Module: Link2
- Defined in:
- lib/link2.rb,
lib/link2/i18n.rb,
lib/link2/brain.rb,
lib/link2/helpers.rb,
lib/link2/support.rb,
lib/link2/version.rb
Defined Under Namespace
Modules: Brain, Helpers, I18n, Support
Constant Summary collapse
- DEFAULT_LINK =
Default URL value; if none can be assumed. Useful value for prototyping.
'#'- DEFAULT_I18N_SCOPE =
Default lookup scope if none is set.
[:links]
- DEFAULT_I18N_SCOPES =
Default I18n lookup scopes if none are set.
[ '{{model}}.links.{{action}}', 'links.{{action}}' ]
- Error =
Class.new(::StandardError)
- NotImplementedYetError =
Class.new(::NotImplementedError)
- DEFAULT_ACTION_MAPPINGS =
Default action mappings: Link value shortcuts sort of. FIXME: DEFAULT_ACTION_MAPPINGS = {
:home => lambda { '/' }, # TODO: Allow named routes, e.g. root_path :back => lambda { |url| url || [:session][:return_to] || :back }}
{ :home => lambda { '/' }, # TODO: Allow named routes, e.g. root_path :back => lambda { |url| url || :back } }
- VERSION =
"0.1.11"- @@i18n_scopes =
DEFAULT_I18N_SCOPES- @@action_mappings =
DEFAULT_ACTION_MAPPINGS- @@dom_selectors =
true
Class Method Summary collapse
-
.setup {|_self| ... } ⇒ Object
Link2.setup do |config| config.i18n_scope = [:actions] end.
-
.url_for_mapping(action, custom_url = nil, options = {}) ⇒ Object
Finds any existing “action mapping” based on a mapping key (custom action).
Class Method Details
.setup {|_self| ... } ⇒ Object
Link2.setup do |config|
config.i18n_scope = [:actions]
end
69 70 71 |
# File 'lib/link2.rb', line 69 def setup yield(self) end |
.url_for_mapping(action, custom_url = nil, options = {}) ⇒ Object
Finds any existing “action mapping” based on a mapping key (custom action).
Example/Usage:
Link2.action_mappings[:back] = lambda { |url| url || session[:return_to] || :back }
url_for_mapping(:back)
# => session[:return_to] || :back
url_for_mapping(:back, "/unicorns")
# => "/unicorns"
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/link2.rb', line 85 def url_for_mapping(action, custom_url = nil, = {}) expression = ::Link2.action_mappings[action] if expression.is_a?(Proc) expression.arity == 0 ? expression.call : expression.call(custom_url) else expression end rescue nil end |