active_scaffold 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +27 -0
- data/CHANGELOG +152 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README +51 -0
- data/Rakefile +24 -0
- data/active_scaffold.gemspec +24 -0
- data/environment.rb +22 -0
- data/frontends/default/images/add.gif +0 -0
- data/frontends/default/images/arrow_down.gif +0 -0
- data/frontends/default/images/arrow_up.gif +0 -0
- data/frontends/default/images/close.gif +0 -0
- data/frontends/default/images/cross.png +0 -0
- data/frontends/default/images/indicator-small.gif +0 -0
- data/frontends/default/images/indicator.gif +0 -0
- data/frontends/default/images/magnifier.png +0 -0
- data/frontends/default/javascripts/jquery/active_scaffold.js +957 -0
- data/frontends/default/javascripts/jquery/jquery.editinplace.js +726 -0
- data/frontends/default/javascripts/prototype/active_scaffold.js +954 -0
- data/frontends/default/javascripts/prototype/dhtml_history.js +867 -0
- data/frontends/default/javascripts/prototype/form_enhancements.js +117 -0
- data/frontends/default/javascripts/prototype/rico_corner.js +370 -0
- data/frontends/default/stylesheets/stylesheet-ie.css +35 -0
- data/frontends/default/stylesheets/stylesheet.css +858 -0
- data/frontends/default/views/_add_existing_form.html.erb +30 -0
- data/frontends/default/views/_base_form.html.erb +41 -0
- data/frontends/default/views/_create_form.html.erb +6 -0
- data/frontends/default/views/_create_form_on_list.html.erb +5 -0
- data/frontends/default/views/_field_search.html.erb +32 -0
- data/frontends/default/views/_form.html.erb +24 -0
- data/frontends/default/views/_form_association.html.erb +14 -0
- data/frontends/default/views/_form_association_footer.html.erb +40 -0
- data/frontends/default/views/_form_attribute.html.erb +15 -0
- data/frontends/default/views/_form_hidden_attribute.html.erb +2 -0
- data/frontends/default/views/_form_messages.html.erb +5 -0
- data/frontends/default/views/_horizontal_subform.html.erb +19 -0
- data/frontends/default/views/_horizontal_subform_header.html.erb +10 -0
- data/frontends/default/views/_horizontal_subform_record.html.erb +37 -0
- data/frontends/default/views/_human_conditions.html.erb +1 -0
- data/frontends/default/views/_list.html.erb +18 -0
- data/frontends/default/views/_list_actions.html.erb +16 -0
- data/frontends/default/views/_list_calculations.html.erb +16 -0
- data/frontends/default/views/_list_column_headings.html.erb +12 -0
- data/frontends/default/views/_list_header.html.erb +12 -0
- data/frontends/default/views/_list_inline_adapter.html.erb +10 -0
- data/frontends/default/views/_list_messages.html.erb +32 -0
- data/frontends/default/views/_list_pagination.html.erb +11 -0
- data/frontends/default/views/_list_pagination_links.html.erb +9 -0
- data/frontends/default/views/_list_record.html.erb +14 -0
- data/frontends/default/views/_list_record_columns.html.erb +8 -0
- data/frontends/default/views/_list_with_header.html.erb +32 -0
- data/frontends/default/views/_messages.html.erb +10 -0
- data/frontends/default/views/_render_field.js.rjs +13 -0
- data/frontends/default/views/_row.html.erb +12 -0
- data/frontends/default/views/_search.html.erb +34 -0
- data/frontends/default/views/_search_attribute.html.erb +10 -0
- data/frontends/default/views/_show.html.erb +8 -0
- data/frontends/default/views/_show_columns.html.erb +12 -0
- data/frontends/default/views/_update_actions.html.erb +9 -0
- data/frontends/default/views/_update_form.html.erb +5 -0
- data/frontends/default/views/_vertical_subform.html.erb +12 -0
- data/frontends/default/views/_vertical_subform_record.html.erb +38 -0
- data/frontends/default/views/add_existing.js.rjs +17 -0
- data/frontends/default/views/add_existing_form.html.erb +5 -0
- data/frontends/default/views/create.html.erb +5 -0
- data/frontends/default/views/delete.html.erb +13 -0
- data/frontends/default/views/destroy.js.rjs +5 -0
- data/frontends/default/views/edit_associated.js.rjs +11 -0
- data/frontends/default/views/field_search.html.erb +5 -0
- data/frontends/default/views/form_messages.js.rjs +1 -0
- data/frontends/default/views/list.html.erb +1 -0
- data/frontends/default/views/list.js.rjs +1 -0
- data/frontends/default/views/on_action_update.js.rjs +8 -0
- data/frontends/default/views/on_create.js.rjs +24 -0
- data/frontends/default/views/on_update.js.rjs +15 -0
- data/frontends/default/views/search.html.erb +5 -0
- data/frontends/default/views/show.html.erb +5 -0
- data/frontends/default/views/update.html.erb +8 -0
- data/frontends/default/views/update_column.js.rjs +13 -0
- data/frontends/default/views/update_row.js.rjs +1 -0
- data/init.rb +1 -0
- data/install_assets.rb +44 -0
- data/lib/active_record_permissions.rb +134 -0
- data/lib/active_scaffold.rb +279 -0
- data/lib/active_scaffold/actions/common_search.rb +22 -0
- data/lib/active_scaffold/actions/core.rb +150 -0
- data/lib/active_scaffold/actions/create.rb +152 -0
- data/lib/active_scaffold/actions/delete.rb +72 -0
- data/lib/active_scaffold/actions/field_search.rb +82 -0
- data/lib/active_scaffold/actions/list.rb +128 -0
- data/lib/active_scaffold/actions/mark.rb +50 -0
- data/lib/active_scaffold/actions/nested.rb +241 -0
- data/lib/active_scaffold/actions/search.rb +47 -0
- data/lib/active_scaffold/actions/show.rb +54 -0
- data/lib/active_scaffold/actions/subform.rb +17 -0
- data/lib/active_scaffold/actions/update.rb +134 -0
- data/lib/active_scaffold/attribute_params.rb +207 -0
- data/lib/active_scaffold/bridges/ancestry/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +38 -0
- data/lib/active_scaffold/bridges/bridge.rb +52 -0
- data/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +16 -0
- data/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +79 -0
- data/lib/active_scaffold/bridges/carrierwave/bridge.rb +7 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +38 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +26 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +35 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +17 -0
- data/lib/active_scaffold/bridges/date_picker/bridge.rb +22 -0
- data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +225 -0
- data/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +22 -0
- data/lib/active_scaffold/bridges/file_column/bridge.rb +11 -0
- data/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb +46 -0
- data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +59 -0
- data/lib/active_scaffold/bridges/file_column/lib/form_ui.rb +37 -0
- data/lib/active_scaffold/bridges/file_column/lib/list_ui.rb +26 -0
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +43 -0
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +9 -0
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +15 -0
- data/lib/active_scaffold/bridges/paperclip/bridge.rb +12 -0
- data/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb +27 -0
- data/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +16 -0
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +38 -0
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +26 -0
- data/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +20 -0
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +187 -0
- data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb +45 -0
- data/lib/active_scaffold/bridges/validation_reflection/bridge.rb +8 -0
- data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +21 -0
- data/lib/active_scaffold/config/base.rb +54 -0
- data/lib/active_scaffold/config/core.rb +229 -0
- data/lib/active_scaffold/config/create.rb +43 -0
- data/lib/active_scaffold/config/delete.rb +25 -0
- data/lib/active_scaffold/config/field_search.rb +74 -0
- data/lib/active_scaffold/config/form.rb +46 -0
- data/lib/active_scaffold/config/list.rb +174 -0
- data/lib/active_scaffold/config/mark.rb +22 -0
- data/lib/active_scaffold/config/nested.rb +43 -0
- data/lib/active_scaffold/config/search.rb +68 -0
- data/lib/active_scaffold/config/show.rb +34 -0
- data/lib/active_scaffold/config/subform.rb +35 -0
- data/lib/active_scaffold/config/update.rb +38 -0
- data/lib/active_scaffold/configurable.rb +29 -0
- data/lib/active_scaffold/constraints.rb +179 -0
- data/lib/active_scaffold/data_structures/action_columns.rb +133 -0
- data/lib/active_scaffold/data_structures/action_link.rb +162 -0
- data/lib/active_scaffold/data_structures/action_links.rb +59 -0
- data/lib/active_scaffold/data_structures/actions.rb +45 -0
- data/lib/active_scaffold/data_structures/column.rb +348 -0
- data/lib/active_scaffold/data_structures/columns.rb +75 -0
- data/lib/active_scaffold/data_structures/error_message.rb +24 -0
- data/lib/active_scaffold/data_structures/nested_info.rb +108 -0
- data/lib/active_scaffold/data_structures/set.rb +62 -0
- data/lib/active_scaffold/data_structures/sorting.rb +168 -0
- data/lib/active_scaffold/finder.rb +333 -0
- data/lib/active_scaffold/helpers/association_helpers.rb +40 -0
- data/lib/active_scaffold/helpers/controller_helpers.rb +40 -0
- data/lib/active_scaffold/helpers/country_helpers.rb +352 -0
- data/lib/active_scaffold/helpers/form_column_helpers.rb +343 -0
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +59 -0
- data/lib/active_scaffold/helpers/id_helpers.rb +131 -0
- data/lib/active_scaffold/helpers/list_column_helpers.rb +363 -0
- data/lib/active_scaffold/helpers/pagination_helpers.rb +55 -0
- data/lib/active_scaffold/helpers/search_column_helpers.rb +238 -0
- data/lib/active_scaffold/helpers/show_column_helpers.rb +46 -0
- data/lib/active_scaffold/helpers/view_helpers.rb +315 -0
- data/lib/active_scaffold/locale/de.rb +113 -0
- data/lib/active_scaffold/locale/en.rb +118 -0
- data/lib/active_scaffold/locale/es.yml +112 -0
- data/lib/active_scaffold/locale/fr.rb +113 -0
- data/lib/active_scaffold/locale/hu.yml +63 -0
- data/lib/active_scaffold/locale/ja.yml +64 -0
- data/lib/active_scaffold/locale/ru.yml +62 -0
- data/lib/active_scaffold/marked_model.rb +38 -0
- data/lib/dhtml_confirm.rb +54 -0
- data/lib/extensions/action_controller_rendering.rb +20 -0
- data/lib/extensions/action_view_rendering.rb +113 -0
- data/lib/extensions/action_view_resolver.rb +7 -0
- data/lib/extensions/active_record_offset.rb +12 -0
- data/lib/extensions/array.rb +7 -0
- data/lib/extensions/localize.rb +10 -0
- data/lib/extensions/name_option_for_datetime.rb +12 -0
- data/lib/extensions/nil_id_in_url_params.rb +7 -0
- data/lib/extensions/paginator_extensions.rb +26 -0
- data/lib/extensions/reverse_associations.rb +62 -0
- data/lib/extensions/routing_mapper.rb +34 -0
- data/lib/extensions/to_label.rb +8 -0
- data/lib/extensions/unsaved_associated.rb +61 -0
- data/lib/extensions/unsaved_record.rb +20 -0
- data/lib/extensions/usa_state.rb +46 -0
- data/lib/generators/active_scaffold/USAGE +29 -0
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +20 -0
- data/lib/generators/active_scaffold_controller/USAGE +19 -0
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +28 -0
- data/lib/generators/active_scaffold_controller/templates/controller.rb +4 -0
- data/lib/generators/active_scaffold_setup/USAGE +10 -0
- data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +53 -0
- data/lib/paginator.rb +136 -0
- data/lib/responds_to_parent.rb +70 -0
- data/public/blank.html +33 -0
- data/shoulda_macros/macros.rb +136 -0
- data/test/bridges/bridge_test.rb +47 -0
- data/test/config/base_test.rb +15 -0
- data/test/config/create_test.rb +55 -0
- data/test/config/list_test.rb +74 -0
- data/test/config/show_test.rb +43 -0
- data/test/config/update_test.rb +17 -0
- data/test/const_mocker.rb +36 -0
- data/test/data_structures/action_columns_test.rb +113 -0
- data/test/data_structures/action_link_test.rb +78 -0
- data/test/data_structures/action_links_test.rb +78 -0
- data/test/data_structures/actions_test.rb +25 -0
- data/test/data_structures/association_column_test.rb +42 -0
- data/test/data_structures/column_test.rb +185 -0
- data/test/data_structures/columns_test.rb +69 -0
- data/test/data_structures/error_message_test.rb +28 -0
- data/test/data_structures/set_test.rb +86 -0
- data/test/data_structures/sorting_test.rb +126 -0
- data/test/data_structures/standard_column_test.rb +24 -0
- data/test/data_structures/virtual_column_test.rb +23 -0
- data/test/extensions/active_record_test.rb +45 -0
- data/test/extensions/array_test.rb +12 -0
- data/test/helpers/form_column_helpers_test.rb +31 -0
- data/test/helpers/list_column_helpers_test.rb +31 -0
- data/test/helpers/pagination_helpers_test.rb +55 -0
- data/test/misc/active_record_permissions_test.rb +154 -0
- data/test/misc/attribute_params_test.rb +110 -0
- data/test/misc/configurable_test.rb +96 -0
- data/test/misc/constraints_test.rb +193 -0
- data/test/misc/finder_test.rb +93 -0
- data/test/misc/lang_test.rb +12 -0
- data/test/mock_app/.gitignore +2 -0
- data/test/mock_app/app/controllers/application_controller.rb +10 -0
- data/test/mock_app/app/helpers/application_helper.rb +3 -0
- data/test/mock_app/config/boot.rb +110 -0
- data/test/mock_app/config/database.yml +16 -0
- data/test/mock_app/config/environment.rb +43 -0
- data/test/mock_app/config/environments/development.rb +17 -0
- data/test/mock_app/config/environments/production.rb +28 -0
- data/test/mock_app/config/environments/test.rb +28 -0
- data/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/mock_app/config/initializers/inflections.rb +10 -0
- data/test/mock_app/config/initializers/mime_types.rb +5 -0
- data/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
- data/test/mock_app/config/initializers/session_store.rb +15 -0
- data/test/mock_app/config/locales/en.yml +5 -0
- data/test/mock_app/config/routes.rb +43 -0
- data/test/mock_app/db/test.sqlite3 +1 -0
- data/test/mock_app/public/blank.html +33 -0
- data/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
- data/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
- data/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +532 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +867 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +117 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +370 -0
- data/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +35 -0
- data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +839 -0
- data/test/model_stub.rb +55 -0
- data/test/run_all.rb +8 -0
- data/test/test_helper.rb +39 -0
- data/uninstall.rb +13 -0
- metadata +478 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
class Object
|
2
|
+
def as_(key, options = {})
|
3
|
+
unless key.blank?
|
4
|
+
text = I18n.translate "#{key}", {:scope => [:active_scaffold], :default => key.is_a?(String) ? key : key.to_s.titleize}.merge(options)
|
5
|
+
# text = nil if text.include?('translation missing:')
|
6
|
+
end
|
7
|
+
text ||= key
|
8
|
+
text
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
class InstanceTag
|
4
|
+
private
|
5
|
+
def datetime_selector_with_name(options, html_options)
|
6
|
+
options.merge!(:prefix => options[:name].gsub(/\[[^\[]*\]$/,'')) if options[:name]
|
7
|
+
datetime_selector_without_name(options, html_options)
|
8
|
+
end
|
9
|
+
alias_method_chain :datetime_selector, :name
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'paginator'
|
2
|
+
|
3
|
+
class Paginator
|
4
|
+
|
5
|
+
# Total number of pages
|
6
|
+
def number_of_pages_with_infinite
|
7
|
+
number_of_pages_without_infinite unless infinite?
|
8
|
+
end
|
9
|
+
alias_method_chain :number_of_pages, :infinite
|
10
|
+
|
11
|
+
# Is this an "infinite" paginator
|
12
|
+
def infinite?
|
13
|
+
@count.nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
class Page
|
17
|
+
# Checks to see if there's a page after this one
|
18
|
+
def next_with_infinite?
|
19
|
+
return true if @pager.infinite?
|
20
|
+
next_without_infinite?
|
21
|
+
end
|
22
|
+
alias_method_chain :next?, :infinite
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Reflection
|
3
|
+
class AssociationReflection #:nodoc:
|
4
|
+
def reverse_for?(klass)
|
5
|
+
reverse_matches_for(klass).empty? ? false : true
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_writer :reverse
|
9
|
+
def reverse
|
10
|
+
if @reverse.nil? and not self.options[:polymorphic]
|
11
|
+
reverse_matches = reverse_matches_for(self.class_name.constantize) rescue nil
|
12
|
+
# grab first association, or make a wild guess
|
13
|
+
@reverse = reverse_matches.blank? ? false : reverse_matches.first.name
|
14
|
+
end
|
15
|
+
@reverse
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def reverse_matches_for(klass)
|
21
|
+
reverse_matches = []
|
22
|
+
|
23
|
+
# stage 1 filter: collect associations that point back to this model and use the same primary_key_name
|
24
|
+
klass.reflect_on_all_associations.each do |assoc|
|
25
|
+
if self.options[:through]
|
26
|
+
# only iterate has_many :through associations
|
27
|
+
next unless assoc.options[:through]
|
28
|
+
next unless assoc.through_reflection.klass == self.through_reflection.klass
|
29
|
+
else
|
30
|
+
# skip over has_many :through associations
|
31
|
+
next if assoc.options[:through]
|
32
|
+
next unless assoc.options[:polymorphic] or assoc.class_name.constantize == self.active_record
|
33
|
+
|
34
|
+
case [assoc.macro, self.macro].find_all{|m| m == :has_and_belongs_to_many}.length
|
35
|
+
# if both are a habtm, then match them based on the join table
|
36
|
+
when 2
|
37
|
+
next unless assoc.options[:join_table] == self.options[:join_table]
|
38
|
+
|
39
|
+
# if only one is a habtm, they do not match
|
40
|
+
when 1
|
41
|
+
next
|
42
|
+
|
43
|
+
# otherwise, match them based on the primary_key_name
|
44
|
+
when 0
|
45
|
+
next unless assoc.primary_key_name.to_sym == self.primary_key_name.to_sym
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
reverse_matches << assoc
|
50
|
+
end
|
51
|
+
|
52
|
+
# stage 2 filter: name-based matching (association name vs self.active_record.to_s)
|
53
|
+
reverse_matches.find_all do |assoc|
|
54
|
+
self.active_record.to_s.underscore.include? assoc.name.to_s.pluralize.singularize
|
55
|
+
end if reverse_matches.length > 1
|
56
|
+
|
57
|
+
reverse_matches
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ActionDispatch
|
2
|
+
module Routing
|
3
|
+
ACTIVE_SCAFFOLD_CORE_ROUTING = {
|
4
|
+
:collection => {:show_search => :get, :render_field => :get},
|
5
|
+
:member => {:row => :get, :update_column => :post, :render_field => :get, :delete => :get}
|
6
|
+
}
|
7
|
+
ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = {
|
8
|
+
:collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post},
|
9
|
+
:member => {:edit_associated => :get, :add_association => :get, :destroy_existing => :delete}
|
10
|
+
}
|
11
|
+
class Mapper
|
12
|
+
module Base
|
13
|
+
def as_routes(options = {:association => true})
|
14
|
+
collection do
|
15
|
+
ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection].each {|name, type| send(type, name)}
|
16
|
+
end
|
17
|
+
member do
|
18
|
+
ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each {|name, type| send(type, name)}
|
19
|
+
end
|
20
|
+
as_association_routes if options[:association]
|
21
|
+
end
|
22
|
+
|
23
|
+
def as_association_routes
|
24
|
+
collection do
|
25
|
+
ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:collection].each {|name, type| send(type, name)}
|
26
|
+
end
|
27
|
+
member do
|
28
|
+
ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each {|name, type| send(type, name)}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# save and validation support for associations.
|
2
|
+
class ActiveRecord::Base
|
3
|
+
def associated_valid?(path = [])
|
4
|
+
return true if path.include?(self) # prevent recursion (if associated and parent are new records)
|
5
|
+
path << self
|
6
|
+
# using [].all? syntax to avoid a short-circuit
|
7
|
+
with_unsaved_associated { |a| [a.valid?, a.associated_valid?(path)].all? {|v| v == true} }
|
8
|
+
end
|
9
|
+
|
10
|
+
def save_associated
|
11
|
+
with_unsaved_associated { |a| a.save and a.save_associated }
|
12
|
+
end
|
13
|
+
|
14
|
+
def save_associated!
|
15
|
+
save_associated or raise(ActiveRecord::RecordNotSaved)
|
16
|
+
end
|
17
|
+
|
18
|
+
def no_errors_in_associated?
|
19
|
+
with_unsaved_associated {|a| a.errors.count == 0 and a.no_errors_in_associated?}
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
# Provide an override to allow the model to restrict which associations are considered
|
25
|
+
# by ActiveScaffolds update mechanism. This allows the model to restrict things like
|
26
|
+
# Acts-As-Versioned versions associations being traversed.
|
27
|
+
#
|
28
|
+
# By defining the method :scaffold_update_nofollow returning an array of associations
|
29
|
+
# these associations will not be traversed.
|
30
|
+
# By defining the method :scaffold_update_follow returning an array of associations,
|
31
|
+
# only those associations will be traversed.
|
32
|
+
#
|
33
|
+
# Otherwise the default behaviour of traversing all associations will be preserved.
|
34
|
+
def associations_for_update
|
35
|
+
if self.respond_to?( :scaffold_update_nofollow )
|
36
|
+
self.class.reflect_on_all_associations.reject { |association| self.scaffold_update_nofollow.include?( association.name ) }
|
37
|
+
elsif self.respond_to?( :scaffold_update_follow )
|
38
|
+
self.class.reflect_on_all_associations.select { |association| self.scaffold_update_follow.include?( association.name ) }
|
39
|
+
else
|
40
|
+
self.class.reflect_on_all_associations
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
# yields every associated object that has been instantiated and is flagged as unsaved.
|
47
|
+
# returns false if any yield returns false.
|
48
|
+
# returns true otherwise, even when none of the associations have been instantiated. build wrapper methods accordingly.
|
49
|
+
def with_unsaved_associated
|
50
|
+
associations_for_update.all? do |association|
|
51
|
+
association_proxy = instance_variable_get("@#{association.name}")
|
52
|
+
if association_proxy
|
53
|
+
records = association_proxy
|
54
|
+
records = [records] unless records.is_a? Array # convert singular associations into collections for ease of use
|
55
|
+
records.select {|r| r.unsaved? and not r.readonly?}.all? {|r| yield r} # must use select instead of find_all, which Rails overrides on association proxies for db access
|
56
|
+
else
|
57
|
+
true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# a simple (manual) unsaved? flag and method. at least it automatically reverts after a save!
|
2
|
+
class ActiveRecord::Base
|
3
|
+
# acts like a dirty? flag, manually thrown during update_record_from_params.
|
4
|
+
def unsaved=(val)
|
5
|
+
@unsaved = (val) ? true : false
|
6
|
+
end
|
7
|
+
|
8
|
+
# whether the unsaved? flag has been thrown
|
9
|
+
def unsaved?
|
10
|
+
@unsaved
|
11
|
+
end
|
12
|
+
|
13
|
+
# automatically unsets the unsaved flag
|
14
|
+
def save_with_unsaved_flag(*args)
|
15
|
+
result = save_without_unsaved_flag(*args)
|
16
|
+
self.unsaved = false
|
17
|
+
return result
|
18
|
+
end
|
19
|
+
alias_method_chain :save, :unsaved_flag
|
20
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
module FormOptionsHelper
|
4
|
+
|
5
|
+
# Return a full select and option tags for the given object and method, using usa_state_options_for_select to generate the list of option <tags>.
|
6
|
+
def usa_state_select(object, method, priority_states = nil, options = {}, html_options = {})
|
7
|
+
InstanceTag.new(object, method, self, options.delete(:object)).to_usa_state_select_tag(priority_states, options, html_options)
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
# Returns a string of option tags for the states in the United States. Supply a state name as +selected to
|
12
|
+
# have it marked as the selected option tag. Included also is the option to set a couple of +priority_states+
|
13
|
+
# in case you want to highligh a local area
|
14
|
+
# NOTE: Only the option tags are returned from this method, wrap it in a <select>
|
15
|
+
def usa_state_options_for_select(selected = nil, priority_states = nil)
|
16
|
+
state_options = ""
|
17
|
+
if priority_states
|
18
|
+
state_options += options_for_select(priority_states, selected)
|
19
|
+
state_options += "<option>-------------</option>\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
if priority_states && priority_states.include?(selected)
|
23
|
+
state_options += options_for_select(USASTATES - priority_states, selected)
|
24
|
+
else
|
25
|
+
state_options += options_for_select(USASTATES, selected)
|
26
|
+
end
|
27
|
+
|
28
|
+
return state_options
|
29
|
+
end
|
30
|
+
|
31
|
+
USASTATES = [["Alabama", "AL"], ["Alaska", "AK"], ["Arizona", "AZ"], ["Arkansas", "AR"], ["California", "CA"], ["Colorado", "CO"], ["Connecticut", "CT"], ["Delaware", "DE"], ["District of Columbia", "DC"], ["Florida", "FL"], ["Georgia", "GA"], ["Hawaii", "HI"], ["Idaho", "ID"], ["Illinois", "IL"], ["Indiana", "IN"], ["Iowa", "IA"], ["Kansas", "KS"], ["Kentucky", "KY"], ["Louisiana", "LA"], ["Maine", "ME"], ["Maryland", "MD"], ["Massachusetts", "MA"], ["Michigan", "MI"], ["Minnesota", "MN"], ["Mississippi", "MS"], ["Missouri", "MO"], ["Montana", "MT"], ["Nebraska", "NE"], ["Nevada", "NV"], ["New Hampshire", "NH"], ["New Jersey", "NJ"], ["New Mexico", "NM"], ["New York", "NY"], ["North Carolina", "NC"], ["North Dakota", "ND"], ["Ohio", "OH"], ["Oklahoma", "OK"], ["Oregon", "OR"], ["Pennsylvania", "PA"], ["Rhode Island", "RI"], ["South Carolina", "SC"], ["South Dakota", "SD"], ["Tennessee", "TN"], ["Texas", "TX"], ["Utah", "UT"], ["Vermont", "VT"], ["Virginia", "VA"], ["Washington", "WA"], ["Wisconsin", "WI"], ["West Virginia", "WV"], ["Wyoming", "WY"]] unless const_defined?("USASTATES")
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
class InstanceTag #:nodoc:
|
36
|
+
include FormOptionsHelper
|
37
|
+
|
38
|
+
def to_usa_state_select_tag(priority_states, options, html_options)
|
39
|
+
html_options = html_options.stringify_keys
|
40
|
+
add_default_name_and_id(html_options)
|
41
|
+
value = value(object) if method(:value).arity > 0
|
42
|
+
content_tag("select", add_options(usa_state_options_for_select(value, priority_states), options, value), html_options)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Description:
|
2
|
+
Scaffolds an entire resource, from model and migration to controller,
|
3
|
+
along with a full test suite and configured to use active_scaffold.
|
4
|
+
The resource is ready to use as a starting point for your RESTful,
|
5
|
+
resource-oriented application.
|
6
|
+
|
7
|
+
Pass the name of the model (in singular form), either CamelCased or
|
8
|
+
under_scored, as the first argument, and an optional list of attribute
|
9
|
+
pairs.
|
10
|
+
|
11
|
+
Attribute pairs are field:type arguments specifying the
|
12
|
+
model's attributes. Timestamps are added by default, so you don't have to
|
13
|
+
specify them by hand as 'created_at:datetime updated_at:datetime'.
|
14
|
+
|
15
|
+
You don't have to think up every attribute up front, but it helps to
|
16
|
+
sketch out a few so you can start working with the resource immediately.
|
17
|
+
|
18
|
+
For example, 'active_scaffold post title:string body:text published:boolean'
|
19
|
+
gives you a model with those three attributes, a controller configured to use active_scaffold,
|
20
|
+
as well as a resources :posts with additional active_scaffold routes
|
21
|
+
declaration in config/routes.rb.
|
22
|
+
|
23
|
+
If you want to remove all the generated files, run
|
24
|
+
'rails destroy active_scaffold ModelName'.
|
25
|
+
|
26
|
+
Examples:
|
27
|
+
`rails generate active_scaffold post`
|
28
|
+
`rails generate active_scaffold post title:string body:text published:boolean`
|
29
|
+
`rails generate active_scaffold purchase order_id:integer amount:decimal`
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails/generators/rails/resource/resource_generator'
|
2
|
+
#require 'generators/active_scaffold_controller/active_scaffold_controller_generator'
|
3
|
+
|
4
|
+
module Rails
|
5
|
+
module Generators
|
6
|
+
class ActiveScaffoldGenerator < ResourceGenerator #metagenerator
|
7
|
+
remove_hook_for :resource_controller
|
8
|
+
remove_class_option :actions
|
9
|
+
|
10
|
+
def add_resource_route
|
11
|
+
route_config = class_path.collect{|namespace| "namespace :#{namespace} do " }.join(" ")
|
12
|
+
route_config << "resources :#{file_name.pluralize} do as_routes end"
|
13
|
+
route_config << " end" * class_path.size
|
14
|
+
route route_config
|
15
|
+
end
|
16
|
+
|
17
|
+
invoke "active_scaffold_controller"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Description:
|
2
|
+
Stubs out a active_scaffolded controller. Pass the model name,
|
3
|
+
either CamelCased or under_scored.
|
4
|
+
The controller name is retrieved as a pluralized version of the model
|
5
|
+
name.
|
6
|
+
|
7
|
+
To create a controller within a module, specify the model name as a
|
8
|
+
path like 'parent_module/controller_name'.
|
9
|
+
|
10
|
+
This generates a controller class in app/controllers and invokes helper,
|
11
|
+
template engine and test framework generators.
|
12
|
+
|
13
|
+
Example:
|
14
|
+
`rails generate active_scaffold_controller CreditCard`
|
15
|
+
|
16
|
+
Credit card controller with URLs like /credit_card/debit.
|
17
|
+
Controller: app/controllers/credit_cards_controller.rb
|
18
|
+
Functional Test: test/functional/credit_cards_controller_test.rb
|
19
|
+
Helper: app/helpers/credit_cards_helper.rb
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Generators
|
5
|
+
class ActiveScaffoldControllerGenerator < NamedBase #metagenerator
|
6
|
+
include ResourceHelpers
|
7
|
+
|
8
|
+
def self.source_root
|
9
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
10
|
+
end
|
11
|
+
|
12
|
+
check_class_collision :suffix => "Controller"
|
13
|
+
|
14
|
+
class_option :orm, :banner => "NAME", :type => :string, :required => true,
|
15
|
+
:desc => "ORM to generate the controller for"
|
16
|
+
|
17
|
+
def create_controller_files
|
18
|
+
template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
|
19
|
+
end
|
20
|
+
|
21
|
+
hook_for :test_framework, :as => :scaffold
|
22
|
+
|
23
|
+
def create_view_root_folder
|
24
|
+
empty_directory File.join("app/views", controller_file_path)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Description:
|
2
|
+
Setup a new Rails 3 Application with active_scaffold.
|
3
|
+
Pass 'jquery' in case you would like to use it instead of prototype
|
4
|
+
|
5
|
+
This installs required plugins and configures active_scaffold to use
|
6
|
+
specified js lib and application layout file to include all required
|
7
|
+
assets
|
8
|
+
|
9
|
+
Example:
|
10
|
+
`rails generate active_scaffold_setup jquery`
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Rails
|
2
|
+
module Generators
|
3
|
+
class ActiveScaffoldSetupGenerator < Rails::Generators::Base #metagenerator
|
4
|
+
argument :js_lib, :type => :string, :default => 'prototype', :desc => 'js_lib for activescaffold (prototype|jquery)'
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
8
|
+
end
|
9
|
+
|
10
|
+
def install_plugins
|
11
|
+
plugin 'verification', :git => 'git://github.com/rails/verification.git'
|
12
|
+
plugin 'render_component', :git => 'git://github.com/vhochstein/render_component.git'
|
13
|
+
if js_lib == 'prototype'
|
14
|
+
get "https://github.com/vhochstein/prototype-ujs/raw/master/src/rails.js", "public/javascripts/rails.js"
|
15
|
+
elsif js_lib == 'jquery'
|
16
|
+
get "https://github.com/vhochstein/jquery-ujs/raw/master/src/rails.js", "public/javascripts/rails_jquery.js"
|
17
|
+
get "https://github.com/vhochstein/jQuery-Timepicker-Addon/raw/master/jquery-ui-timepicker-addon.js", "public/javascripts/jquery-ui-timepicker-addon.js"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure_active_scaffold
|
22
|
+
if js_lib == 'jquery'
|
23
|
+
gsub_file 'vendor/plugins/active_scaffold/environment.rb', /#ActiveScaffold.js_framework = :jquery/, 'ActiveScaffold.js_framework = :jquery'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def configure_application_layout
|
28
|
+
if js_lib == 'prototype'
|
29
|
+
inject_into_file "app/views/layouts/application.html.erb",
|
30
|
+
" <%= active_scaffold_includes %>\n",
|
31
|
+
:after => "<%= javascript_include_tag :defaults %>\n"
|
32
|
+
elsif js_lib == 'jquery'
|
33
|
+
inject_into_file "app/views/layouts/application.html.erb",
|
34
|
+
" <%= stylesheet_link_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/ui-lightness/jquery-ui.css' %>
|
35
|
+
<%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js' %>
|
36
|
+
<%= javascript_include_tag 'rails_jquery.js' %>
|
37
|
+
<%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.js' %>
|
38
|
+
<%= javascript_include_tag 'jquery-ui-timepicker-addon.js' %>
|
39
|
+
<%= javascript_include_tag 'application.js' %>
|
40
|
+
<%= active_scaffold_includes %>\n",
|
41
|
+
:after => "<%= javascript_include_tag :defaults %>\n"
|
42
|
+
|
43
|
+
inject_into_file "config/locales/en.yml",
|
44
|
+
" time:
|
45
|
+
formats:
|
46
|
+
default: \"%a, %d %b %Y %H:%M:%S\"",
|
47
|
+
:after => "hello: \"Hello world\"\n"
|
48
|
+
gsub_file 'app/views/layouts/application.html.erb', /<%= javascript_include_tag :defaults/, '<%# javascript_include_tag :defaults'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|