hobo 1.3.0.RC4 → 1.3.0.pre10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +234 -282
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/app/controllers/dev_controller.rb +2 -2
- data/bin/hobo +3 -3
- data/config/routes.rb +1 -1
- data/doctests/hobo/lifecycles.rdoctest +1 -0
- data/doctests/hobo/model.rdoctest +5 -0
- data/doctests/hobo/multi_model_forms.rdoctest +5 -4
- data/doctests/hobo/scopes.rdoctest +8 -11
- data/doctests/prepare_testapp.rb +1 -2
- data/hobo.gemspec +2 -2
- data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +11 -5
- data/lib/generators/hobo/admin_subsite/templates/admin.css +2 -20
- data/lib/generators/hobo/admin_subsite/templates/admin_tag_injection.erb +1 -3
- data/lib/generators/hobo/admin_subsite/templates/controller.rb.erb +5 -5
- data/lib/generators/hobo/admin_subsite/templates/users_index.dryml +1 -3
- data/lib/generators/hobo/basic/basic_generator.rb +17 -0
- data/lib/generators/hobo/{assets → basic}/templates/application.css +0 -0
- data/lib/generators/hobo/{assets → basic}/templates/application.dryml.erb +1 -1
- data/lib/generators/hobo/{assets → basic}/templates/dryml-support.js +2 -2
- data/lib/generators/hobo/{assets → basic}/templates/en_injection.yml +0 -0
- data/lib/generators/hobo/{assets → basic}/templates/guest.rb +0 -0
- data/lib/generators/hobo/controller.rb +1 -6
- data/lib/generators/hobo/front_controller/front_controller_generator.rb +3 -2
- data/{app/views/dev → lib/generators/hobo/front_controller/templates}/summary.dryml +10 -7
- data/lib/generators/hobo/hints/hints_generator.rb +12 -0
- data/lib/generators/hobo/hints/templates/hints.rb.erb +5 -0
- data/lib/generators/hobo/hints/templates/model_injection.rb.erb +36 -0
- data/lib/generators/hobo/i18n/i18n_generator.rb +9 -1
- data/lib/generators/hobo/i18n/templates/app.en.yml +1 -1
- data/lib/generators/hobo/i18n/templates/app.es-DO.yml +24 -0
- data/lib/generators/hobo/i18n/templates/app.it.yml +1 -5
- data/lib/generators/hobo/i18n/templates/app.pt-PT.yml +0 -1
- data/lib/generators/hobo/i18n/templates/default_count_injection.rb +10 -0
- data/lib/generators/hobo/i18n/templates/hobo.en.yml +10 -26
- data/lib/generators/hobo/i18n/templates/{hobo.es.yml → hobo.es-DO.yml} +10 -27
- data/lib/generators/hobo/i18n/templates/hobo.it.yml +4 -20
- data/lib/generators/hobo/i18n/templates/hobo.pt-PT.yml +9 -25
- data/lib/generators/hobo/model.rb +13 -0
- data/lib/generators/hobo/model/USAGE +3 -2
- data/lib/generators/hobo/model/model_generator.rb +1 -2
- data/lib/generators/hobo/rapid/rapid_generator.rb +0 -2
- data/lib/generators/hobo/rapid/templates/hobo-rapid.js +93 -78
- data/lib/generators/hobo/rapid/templates/ie7-recalc.js +21 -21
- data/lib/generators/hobo/rapid/templates/lowpro.js +31 -31
- data/lib/generators/hobo/rapid/templates/reset.css +1 -1
- data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/clean.css +16 -17
- data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +3 -3
- data/lib/generators/hobo/rapid/templates/themes/clean/views/clean.dryml +1 -1
- data/lib/generators/hobo/resource/resource_generator.rb +1 -1
- data/lib/generators/hobo/routes/router.rb +4 -4
- data/lib/generators/hobo/routes/routes_generator.rb +1 -12
- data/lib/generators/hobo/routes/templates/hobo_routes.rb.erb +1 -1
- data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +43 -88
- data/lib/generators/hobo/subsite.rb +5 -18
- data/lib/generators/hobo/subsite/subsite_generator.rb +1 -1
- data/lib/generators/hobo/subsite/templates/controller.rb.erb +1 -1
- data/lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb +2 -2
- data/lib/generators/hobo/test_framework/test_framework_generator.rb +7 -7
- data/lib/generators/hobo/user_controller/templates/controller.rb.erb +3 -8
- data/lib/generators/hobo/user_mailer/templates/activation.erb +2 -2
- data/lib/generators/hobo/user_mailer/templates/forgot_password.erb +2 -2
- data/lib/generators/hobo/user_mailer/templates/invite.erb +2 -2
- data/lib/generators/hobo/user_mailer/templates/mailer.rb.erb +17 -10
- data/lib/generators/hobo/user_mailer/user_mailer_generator.rb +1 -1
- data/lib/generators/hobo/user_model/USAGE +9 -2
- data/lib/generators/hobo/user_model/user_model_generator.rb +1 -2
- data/lib/hobo.rb +7 -13
- data/lib/hobo/controller.rb +14 -21
- data/lib/hobo/controller/authentication_support.rb +23 -1
- data/lib/hobo/controller/model.rb +53 -48
- data/lib/hobo/controller/{user_base.rb → user.rb} +36 -47
- data/lib/hobo/engine.rb +11 -25
- data/lib/hobo/extensions/action_controller/hobo_methods.rb +1 -25
- data/lib/hobo/extensions/active_model/translation.rb +1 -1
- data/lib/hobo/extensions/active_record/{associations/collection.rb → association_collection.rb} +3 -12
- data/lib/hobo/extensions/active_record/{associations/proxy.rb → association_proxy.rb} +7 -6
- data/lib/hobo/extensions/active_record/association_reflection.rb +19 -0
- data/lib/hobo/extensions/active_record/hobo_methods.rb +1 -1
- data/lib/hobo/extensions/active_record/scopes.rb +31 -0
- data/lib/hobo/extensions/array.rb +1 -13
- data/lib/hobo/helper.rb +6 -27
- data/lib/hobo/helper/translations.rb +90 -39
- data/lib/hobo/model.rb +20 -72
- data/lib/hobo/model/lifecycles.rb +11 -12
- data/lib/hobo/model/lifecycles/lifecycle.rb +4 -12
- data/lib/hobo/model/lifecycles/transition.rb +0 -1
- data/lib/hobo/model/permissions.rb +3 -2
- data/lib/hobo/model/scopes/apply_scopes.rb +1 -1
- data/lib/hobo/model/scopes/automatic_scopes.rb +80 -78
- data/lib/hobo/model/{user_base.rb → user.rb} +7 -9
- data/lib/hobo/rapid/generators/rapid/cards.dryml.erb +2 -2
- data/lib/hobo/rapid/generators/rapid/forms.dryml.erb +4 -5
- data/lib/hobo/rapid/generators/rapid/pages.dryml.erb +27 -26
- data/lib/hobo/rapid/helper.rb +5 -10
- data/lib/hobo/rapid/taglibs/rapid.dryml +1 -1
- data/lib/hobo/rapid/taglibs/rapid_core.dryml +42 -72
- data/lib/hobo/rapid/taglibs/rapid_document_tags.dryml +2 -2
- data/lib/hobo/rapid/taglibs/rapid_editing.dryml +16 -36
- data/lib/hobo/rapid/taglibs/rapid_forms.dryml +49 -87
- data/lib/hobo/rapid/taglibs/rapid_generics.dryml +2 -2
- data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +75 -50
- data/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml +5 -7
- data/lib/hobo/rapid/taglibs/rapid_navigation.dryml +2 -2
- data/lib/hobo/rapid/taglibs/rapid_pages.dryml +7 -8
- data/lib/hobo/rapid/taglibs/rapid_plus.dryml +43 -66
- data/lib/hobo/rapid/taglibs/rapid_summary.dryml +45 -16
- data/lib/hobo/rapid/taglibs/rapid_translations.dryml +36 -0
- data/lib/hobo/rapid/taglibs/rapid_user_pages.dryml +8 -8
- data/lib/hobo/routes.rb +23 -22
- data/lib/hobo/view_hints.rb +101 -0
- data/test/irt/generators/admin_subsite.irt +1 -1
- data/test/irt/generators/{assets.irt → basic.irt} +2 -2
- data/test/irt/generators/front_controller.irt +4 -2
- data/test/irt/generators/partials/_subsite_taglib_variables.rb +1 -1
- data/test/irt/generators/subsite.irt +1 -1
- data/test/permissions/test_permissions.rb +103 -103
- metadata +108 -69
- data/lib/generators/hobo/admin_subsite/USAGE +0 -25
- data/lib/generators/hobo/admin_subsite/templates/application.dryml +0 -1
- data/lib/generators/hobo/assets/USAGE +0 -5
- data/lib/generators/hobo/assets/assets_generator.rb +0 -18
- data/lib/generators/hobo/assets/templates/dryml_taglibs_initializer.rb +0 -1
- data/lib/generators/hobo/controller/USAGE +0 -3
- data/lib/generators/hobo/i18n/USAGE +0 -3
- data/lib/generators/hobo/i18n/templates/app.de.yml +0 -30
- data/lib/generators/hobo/i18n/templates/app.es.yml +0 -31
- data/lib/generators/hobo/i18n/templates/app.fr.yml +0 -26
- data/lib/generators/hobo/i18n/templates/app.nb.yml +0 -25
- data/lib/generators/hobo/i18n/templates/app.ru.yml +0 -24
- data/lib/generators/hobo/i18n/templates/hobo.de.yml +0 -204
- data/lib/generators/hobo/i18n/templates/hobo.fr.yml +0 -195
- data/lib/generators/hobo/i18n/templates/hobo.nb.yml +0 -198
- data/lib/generators/hobo/i18n/templates/hobo.ru.yml +0 -200
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-ACD3E6-DBE1E5-H.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-DBE1E5-FCFEF5-H.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/300-3B5F87-ACD3E6-H.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/spinner.gif +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/stylesheets/clean-sidemenu.css +0 -81
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/views/clean-sidemenu.dryml +0 -30
- data/lib/generators/hobo/resource/USAGE +0 -39
- data/lib/generators/hobo/subsite/USAGE +0 -24
- data/lib/generators/hobo/subsite_taglib/USAGE +0 -4
- data/lib/generators/hobo/test_framework/USAGE +0 -2
- data/lib/generators/hobo/user_controller/USAGE +0 -3
- data/lib/generators/hobo/user_mailer/USAGE +0 -2
- data/lib/generators/hobo/user_resource/USAGE +0 -10
- data/lib/hobo/extensions/action_view/translation_helper.rb +0 -25
- data/lib/hobo/extensions/active_record/associations/reflection.rb +0 -23
- data/lib/hobo/extensions/active_record/associations/scope.rb +0 -35
- data/lib/hobo/extensions/active_record/relation_with_origin.rb +0 -32
- data/lib/hobo/extensions/i18n.rb +0 -17
- data/lib/hobo/helper/translations/normalizer.rb +0 -39
- data/lib/hobo/model/view_hints.rb +0 -123
@@ -1,30 +0,0 @@
|
|
1
|
-
<extend tag="page" attrs="title, full-title">
|
2
|
-
<old-page merge title="&title" full-title="&full_title">
|
3
|
-
|
4
|
-
<stylesheets: param>
|
5
|
-
<stylesheet name="reset"/>
|
6
|
-
<theme-stylesheet/>
|
7
|
-
<stylesheet name="application" param="app-stylesheet"/>
|
8
|
-
</stylesheets:>
|
9
|
-
|
10
|
-
<header: class="sidemenu" param>
|
11
|
-
<live-search param if="&defined_route? :site_search"/>
|
12
|
-
<account-nav if="&login_url(Hobo::Model::UserBase.default_user_model)" param/>
|
13
|
-
<h1 param="app-name"><a href="#{base_url}/"><app-name/></a></h1>
|
14
|
-
</header:>
|
15
|
-
|
16
|
-
<content: replace>
|
17
|
-
<table id="container">
|
18
|
-
<tr>
|
19
|
-
<td id="main-nav-container">
|
20
|
-
<main-nav current="&title" param/>
|
21
|
-
</td>
|
22
|
-
<td id="content-container">
|
23
|
-
<section with-flash-messages param="content"/>
|
24
|
-
</td>
|
25
|
-
</tr>
|
26
|
-
</table>
|
27
|
-
</content:>
|
28
|
-
|
29
|
-
</old-page>
|
30
|
-
</extend>
|
@@ -1,39 +0,0 @@
|
|
1
|
-
Description:
|
2
|
-
The model generator creates stubs for a new model, corresponding
|
3
|
-
controller and it's views.
|
4
|
-
|
5
|
-
The generator takes a model name as its argument. The model name
|
6
|
-
may be given in CamelCase or under_score and should not be
|
7
|
-
suffixed with anything.
|
8
|
-
|
9
|
-
As additional parameters, the generator will take attribute pairs
|
10
|
-
described by name and type. These attributes will be used to
|
11
|
-
prepopulate the migration to create the table for the model and
|
12
|
-
give you a set of predefined fixture. You don't have to think up
|
13
|
-
all attributes up front, but it's a good idea to add just the
|
14
|
-
baseline of what's needed to start really working with the
|
15
|
-
resource.
|
16
|
-
|
17
|
-
The generator creates a model class in app/models, a test suite in
|
18
|
-
test/unit and test fixtures in test/fixtures/singular_name.yml.
|
19
|
-
The generator creates a controller class in app/controllers with
|
20
|
-
view templates in app/views/controller_name, a helper class in
|
21
|
-
app/helpers, and a functional test suite in test/functional.
|
22
|
-
|
23
|
-
Examples:
|
24
|
-
rails generate hobo:resource account
|
25
|
-
|
26
|
-
This will create an Account model:
|
27
|
-
Model: app/models/account.rb
|
28
|
-
Controller: app/controllers/accounts_controller.rb
|
29
|
-
Helper: app/helpers/accounts_helper.rb
|
30
|
-
Views: app/views/accounts
|
31
|
-
Test: test/unit/account_test.rb
|
32
|
-
Test: test/functions/accounts_controller_test.rb
|
33
|
-
Fixtures: test/fixtures/accounts.yml
|
34
|
-
|
35
|
-
(files generated may vary depending on test suite & fixture configuration)
|
36
|
-
|
37
|
-
rails generate hobo:resource post title:string created_on:date body:text published:boolean
|
38
|
-
|
39
|
-
Creates post model, controller & views with predefined attributes.
|
@@ -1,24 +0,0 @@
|
|
1
|
-
Description:
|
2
|
-
|
3
|
-
Creates a subsite, a namespaced section of your application.
|
4
|
-
|
5
|
-
Controllers for the subsite are created in
|
6
|
-
app/controllers/<subsite_name>/ and views are also in their own
|
7
|
-
subdirectory. This allows you to have two different controllers
|
8
|
-
and two different sets of views for the same model.
|
9
|
-
|
10
|
-
The subsite will use app/views/taglibs/<subsite_name>_site.dryml
|
11
|
-
as well as app/views/taglibs/application.dryml. This allows you
|
12
|
-
to customize the look and feel of a portion of your site. The
|
13
|
-
remaining views of your application that are not under a subsite
|
14
|
-
load both application.dryml and front_site.dryml.
|
15
|
-
|
16
|
-
It is thus recommended that you ensure that
|
17
|
-
<subsite_name>_site.dryml and application.dryml do not repeat
|
18
|
-
code, such as the inclusion of rapid or the setting of the theme.
|
19
|
-
One easy way of ensuring this is to use the --make-front-site
|
20
|
-
option. If you have already accounted for this, use
|
21
|
-
--make-front-site=false.
|
22
|
-
|
23
|
-
The difference between hobo:admin_site and hobo:subsite is that
|
24
|
-
hobo:admin_site limits the subsite to use by administrators only.
|
@@ -1,25 +0,0 @@
|
|
1
|
-
ActionView::Helpers::TranslationHelper.module_eval do
|
2
|
-
|
3
|
-
# simple wrapper around the translate helper
|
4
|
-
# it implements a dryml <translate> and a <t> tag
|
5
|
-
# Improved security: interpolated variables are escaped
|
6
|
-
# Improved management: when it returns a string it is always html_safe
|
7
|
-
# It assumes the base translation string is html_safe
|
8
|
-
# It removes the <span> tag when the key is missing, because it would mess up
|
9
|
-
# the dryml tags when ht or t is used in some place
|
10
|
-
|
11
|
-
def translate(key, options={})
|
12
|
-
key, options = normalize_args(key, options)
|
13
|
-
translation = I18n.translate(scope_key_by_partial(key), options.merge!(:raise => true))
|
14
|
-
if translation.respond_to?(:html_safe)
|
15
|
-
translation.html_safe
|
16
|
-
else
|
17
|
-
translation
|
18
|
-
end
|
19
|
-
rescue I18n::MissingTranslationData => e
|
20
|
-
keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope]).join('.')
|
21
|
-
"[MISSING: #{keys}]"
|
22
|
-
end
|
23
|
-
alias_method :t, :translate
|
24
|
-
|
25
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Reflection
|
3
|
-
class AssociationReflection
|
4
|
-
|
5
|
-
alias_method :association_name, :name
|
6
|
-
|
7
|
-
def klass_with_create_polymorphic_class
|
8
|
-
if options[:polymorphic]
|
9
|
-
begin
|
10
|
-
klass_without_create_polymorphic_class
|
11
|
-
rescue NameError => e
|
12
|
-
Object.class_eval "class #{e.missing_name} < ActiveRecord::Base; set_table_name '#{active_record.name.tableize}'; def self.hobo_shim?; true; end; end"
|
13
|
-
e.missing_name.constantize
|
14
|
-
end
|
15
|
-
else
|
16
|
-
klass_without_create_polymorphic_class
|
17
|
-
end
|
18
|
-
end
|
19
|
-
alias_method_chain :klass, :create_polymorphic_class
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# Add support for :scope => :my_scope to associations
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module Associations
|
5
|
-
module ThroughAssociationScope
|
6
|
-
|
7
|
-
def construct_scope_with_scope
|
8
|
-
s = construct_scope_without_scope
|
9
|
-
s[:find][:scope] = @reflection.options[:scope]
|
10
|
-
s
|
11
|
-
end
|
12
|
-
alias_method_chain :construct_scope, :scope
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
module SpawnMethods
|
18
|
-
|
19
|
-
def apply_finder_options_with_scope(options)
|
20
|
-
scopes = []
|
21
|
-
Array.wrap(options.delete(:scope)).each do |s|
|
22
|
-
if s.is_a?(Hash)
|
23
|
-
s.each_pair{|k,v| scopes << [k,v] }
|
24
|
-
else
|
25
|
-
scopes << [s]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
relation = apply_finder_options_without_scope(options)
|
29
|
-
return relation if scopes.empty?
|
30
|
-
scopes.inject(relation) {|r, s| r.send *s }
|
31
|
-
end
|
32
|
-
alias_method_chain :apply_finder_options, :scope
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
|
3
|
-
class Relation
|
4
|
-
attr_accessor :origin, :origin_attribute
|
5
|
-
|
6
|
-
def member_class
|
7
|
-
@klass
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
module Associations
|
12
|
-
class AssociationCollection
|
13
|
-
|
14
|
-
def scoped_with_origin
|
15
|
-
relation = scoped_without_origin.clone
|
16
|
-
relation.origin = @owner
|
17
|
-
relation.origin_attribute = @reflection.name
|
18
|
-
relation
|
19
|
-
end
|
20
|
-
alias_method_chain :scoped, :origin
|
21
|
-
|
22
|
-
def method_missing_with_origin(method, *args, &block)
|
23
|
-
res = method_missing_without_origin(method, *args, &block)
|
24
|
-
res.origin = @owner if res.respond_to?(:origin)
|
25
|
-
res.origin_attribute = @reflection.name if res.respond_to?(:origin_attribute)
|
26
|
-
res
|
27
|
-
end
|
28
|
-
alias_method_chain :method_missing, :origin
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/lib/hobo/extensions/i18n.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
I18n.module_eval do
|
2
|
-
class << self
|
3
|
-
|
4
|
-
def translate_with_show_keys(key, options = {})
|
5
|
-
translation = translate_without_show_keys(key, options)
|
6
|
-
return translation unless translation.is_a?(String)
|
7
|
-
keys = normalize_keys(locale, key, options[:scope]).join('.')
|
8
|
-
"[#{keys}]" + translation
|
9
|
-
end
|
10
|
-
alias_method_chain :translate, :show_keys
|
11
|
-
|
12
|
-
alias_method :t_without_show_keys, :t
|
13
|
-
alias_method :t, :translate_with_show_keys
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/string/output_safety'
|
2
|
-
module Hobo
|
3
|
-
module Helper
|
4
|
-
module Translations
|
5
|
-
module Normalizer
|
6
|
-
|
7
|
-
private
|
8
|
-
|
9
|
-
def normalize_args(key, options={})
|
10
|
-
if (key.class == Hash) # called as a tag
|
11
|
-
if key.has_key?(:default) && !key[:default].blank?
|
12
|
-
Rails.logger.warn "hobo-i18n: 'default' should not be used as an attribute on *translate tags. If used, then you need to make sure that the tags inner-contents are not used. These are normally treated as defaults automatically, but if there is a default attribute then that inner-content will be hidden from this method - and will not be replaced with the translation found."
|
13
|
-
end
|
14
|
-
defaults = options[:default]
|
15
|
-
options = key
|
16
|
-
key = options.delete(:key)
|
17
|
-
# Set options[:default] to complete the tag-argument-conversion process.
|
18
|
-
options[:default] = defaults.call(options) if defaults.class == Proc
|
19
|
-
end
|
20
|
-
escape_options(options)
|
21
|
-
options[:default] = Array.wrap options[:default]
|
22
|
-
[key, options]
|
23
|
-
end
|
24
|
-
|
25
|
-
def escape_options(options)
|
26
|
-
options.each_pair do |k,v|
|
27
|
-
options[k] = case v
|
28
|
-
when Array
|
29
|
-
v.map {|i| i.respond_to?(:html_safe) ? ERB::Util.html_escape(i) : i}
|
30
|
-
else
|
31
|
-
v.respond_to?(:html_safe) ? ERB::Util.html_escape(v) : v
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,123 +0,0 @@
|
|
1
|
-
module Hobo
|
2
|
-
module Model
|
3
|
-
class ViewHints
|
4
|
-
|
5
|
-
class << self
|
6
|
-
|
7
|
-
# allows delayed set of children in order to avoid circular references
|
8
|
-
# triggered by declaring children in the model
|
9
|
-
def children(*args)
|
10
|
-
if args.empty? # reader
|
11
|
-
if @children_args.nil? # value already set
|
12
|
-
@children ||= []
|
13
|
-
else # set
|
14
|
-
child_model = model.reflect_on_association(@children_args.first).klass
|
15
|
-
if child_model.view_hints.parent.nil? and !child_model.view_hints.parent_defined
|
16
|
-
parent = model.reverse_reflection(@children_args.first)
|
17
|
-
child_model.view_hints.parent(parent.name, :undefined => true) if parent
|
18
|
-
end
|
19
|
-
@children = @children_args
|
20
|
-
@children_args = nil
|
21
|
-
@children
|
22
|
-
end
|
23
|
-
else # writer (only stores the args for delayed setting)
|
24
|
-
@children_args = args
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def inline_booleans(*args)
|
29
|
-
if args.empty? # reader
|
30
|
-
if @inline_booleans_args.nil?
|
31
|
-
@inline_booleans ||= []
|
32
|
-
else
|
33
|
-
@inline_booleans = if @inline_booleans_args.first == true
|
34
|
-
model.columns.select { |c| c.type == :boolean }.*.name
|
35
|
-
else
|
36
|
-
@inline_booleans_args.*.to_s
|
37
|
-
end
|
38
|
-
@inline_booleans_args = nil
|
39
|
-
@inline_booleans
|
40
|
-
end
|
41
|
-
else # writer
|
42
|
-
@inline_booleans_args = args
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def parent(*args)
|
47
|
-
if args.empty? #reader
|
48
|
-
@parent
|
49
|
-
else # writer
|
50
|
-
options = args.extract_options!
|
51
|
-
parent_defined(true) unless options[:undefined]
|
52
|
-
@parent = args.first
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def parent_defined(arg=nil)
|
57
|
-
if arg.nil?
|
58
|
-
@parent_defined
|
59
|
-
else
|
60
|
-
@parent_defined = arg
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def paginate?(arg=nil)
|
65
|
-
if arg.nil?
|
66
|
-
@paginate ||= !sortable?
|
67
|
-
else
|
68
|
-
@paginate = arg
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def sortable?(arg=nil)
|
73
|
-
if arg.nil?
|
74
|
-
@sortable ||= defined?(ActiveRecord::Acts::List::InstanceMethods) &&
|
75
|
-
model < ActiveRecord::Acts::List::InstanceMethods &&
|
76
|
-
model.table_exists? &&
|
77
|
-
model.new.try.scope_condition == "1 = 1"
|
78
|
-
else
|
79
|
-
@sortable = arg
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def _name
|
84
|
-
@_name ||= name.sub(/Hints$/, '')
|
85
|
-
end
|
86
|
-
|
87
|
-
def model
|
88
|
-
@model ||= _name.constantize
|
89
|
-
end
|
90
|
-
|
91
|
-
def primary_children
|
92
|
-
children.first
|
93
|
-
end
|
94
|
-
|
95
|
-
def secondary_children
|
96
|
-
children.rest
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
##### LEGACY METHODS TO REMOVE #####
|
101
|
-
|
102
|
-
def model_name(*)
|
103
|
-
raise NotImplementedError, "ViewHints.model_name is no longer supported, please use model.model_name.human and set a the activerecord.models.<model_name> key in a locale file"
|
104
|
-
end
|
105
|
-
|
106
|
-
def model_name_plural(*)
|
107
|
-
raise NotImplementedError, "ViewHints.model_name_plural is no longer supported, please use model.model_name.human(:count => n) and set a the activerecord.models.<model_name> key in a locale file"
|
108
|
-
end
|
109
|
-
|
110
|
-
def field_name(*)
|
111
|
-
raise NotImplementedError, "ViewHints.field_name is no longer supported, please use model..human_attribute_name and set a the activerecord.attributes.<model_name>.<field_name> key in a locale file"
|
112
|
-
end
|
113
|
-
|
114
|
-
def field_names(*)
|
115
|
-
raise NotImplementedError, "ViewHints.field_names is no longer supported, please set the activerecord.attributes.<model_name>.<field_name> keys in a locale file"
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
end
|