dry_crud 0.6.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. data/README.rdoc +41 -36
  2. data/Rakefile +51 -43
  3. data/VERSION +1 -1
  4. data/lib/generators/dry_crud/USAGE +1 -0
  5. data/lib/generators/dry_crud/dry_crud_generator.rb +20 -0
  6. data/{rails_generators → lib/generators}/dry_crud/templates/INSTALL +4 -3
  7. data/{rails_generators → lib/generators}/dry_crud/templates/app/controllers/crud_controller.rb +31 -9
  8. data/lib/generators/dry_crud/templates/app/controllers/render_inheritable.rb +152 -0
  9. data/{rails_generators → lib/generators}/dry_crud/templates/app/helpers/crud_helper.rb +4 -4
  10. data/{rails_generators/dry_crud/templates/lib → lib/generators/dry_crud/templates/app/helpers}/standard_form_builder.rb +0 -0
  11. data/{rails_generators → lib/generators}/dry_crud/templates/app/helpers/standard_helper.rb +81 -76
  12. data/{rails_generators/dry_crud/templates/lib → lib/generators/dry_crud/templates/app/helpers}/standard_table_builder.rb +45 -46
  13. data/{rails_generators → lib/generators}/dry_crud/templates/app/views/crud/_attrs.html.erb +0 -0
  14. data/lib/generators/dry_crud/templates/app/views/crud/_form.html.erb +1 -0
  15. data/{rails_generators → lib/generators}/dry_crud/templates/app/views/crud/_list.html.erb +0 -0
  16. data/{rails_generators → lib/generators}/dry_crud/templates/app/views/crud/edit.html.erb +1 -1
  17. data/{rails_generators → lib/generators}/dry_crud/templates/app/views/crud/index.html.erb +1 -1
  18. data/{rails_generators → lib/generators}/dry_crud/templates/app/views/crud/new.html.erb +1 -1
  19. data/{rails_generators → lib/generators}/dry_crud/templates/app/views/crud/show.html.erb +1 -1
  20. data/{rails_generators → lib/generators}/dry_crud/templates/app/views/layouts/crud.html.erb +1 -0
  21. data/lib/generators/dry_crud/templates/app/views/shared/_error_messages.html.erb +10 -0
  22. data/lib/generators/dry_crud/templates/app/views/shared/_labeled.html.erb +4 -0
  23. data/{rails_generators → lib/generators}/dry_crud/templates/public/stylesheets/crud.css +5 -5
  24. data/{rails_generators → lib/generators}/dry_crud/templates/test/crud_test_model.rb +25 -17
  25. data/{rails_generators → lib/generators}/dry_crud/templates/test/functional/crud_controller_test_helper.rb +36 -32
  26. data/{rails_generators → lib/generators}/dry_crud/templates/test/functional/crud_test_models_controller_test.rb +17 -4
  27. data/{rails_generators → lib/generators}/dry_crud/templates/test/unit/crud_helper_test.rb +51 -6
  28. data/{rails_generators → lib/generators}/dry_crud/templates/test/unit/render_inheritable_test.rb +31 -39
  29. data/{rails_generators → lib/generators}/dry_crud/templates/test/unit/standard_form_builder_test.rb +0 -0
  30. data/{rails_generators → lib/generators}/dry_crud/templates/test/unit/standard_helper_test.rb +76 -54
  31. data/{rails_generators → lib/generators}/dry_crud/templates/test/unit/standard_table_builder_test.rb +42 -40
  32. data/test/templates/app/views/ajax/ajax.js.rjs +1 -1
  33. data/test/templates/app/views/ajax/index.html.erb +2 -2
  34. data/test/templates/app/views/cities/_form.html.erb +1 -1
  35. data/test/templates/app/views/cities/_list.html.erb +1 -2
  36. data/test/templates/config/routes.rb +14 -5
  37. metadata +51 -37
  38. data/rails_generators/dry_crud/USAGE +0 -1
  39. data/rails_generators/dry_crud/dry_crud_generator.rb +0 -22
  40. data/rails_generators/dry_crud/templates/app/views/crud/_form.html.erb +0 -1
  41. data/rails_generators/dry_crud/templates/app/views/shared/_labeled.html.erb +0 -5
  42. data/rails_generators/dry_crud/templates/lib/crud_callbacks.rb +0 -55
  43. data/rails_generators/dry_crud/templates/lib/render_inheritable.rb +0 -118
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry_crud
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 6
9
9
  - 0
10
- version: 0.6.0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pascal Zumkehr
@@ -15,12 +15,26 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-10 00:00:00 +02:00
18
+ date: 2010-08-31 00:00:00 +02:00
19
19
  default_executable:
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ version: "3.0"
34
+ type: :runtime
35
+ version_requirements: *id001
22
36
  description: |
23
- Generates DRY but extendable CRUD controller, views and helpers for Rails applications
37
+ Generates simple and extendable controller, views and helpers that support you to DRY up the CRUD code in your Rails project. Start with these elements and build a clean base to efficiently develop your application upon.
24
38
 
25
39
  email: spam@codez.ch
26
40
  executables: []
@@ -32,34 +46,34 @@ extra_rdoc_files:
32
46
  - README.rdoc
33
47
  - VERSION
34
48
  files:
35
- - rails_generators/dry_crud/dry_crud_generator.rb
36
- - rails_generators/dry_crud/templates/app/controllers/crud_controller.rb
37
- - rails_generators/dry_crud/templates/app/helpers/crud_helper.rb
38
- - rails_generators/dry_crud/templates/app/helpers/standard_helper.rb
39
- - rails_generators/dry_crud/templates/app/views/crud/_attrs.html.erb
40
- - rails_generators/dry_crud/templates/app/views/crud/_form.html.erb
41
- - rails_generators/dry_crud/templates/app/views/crud/_list.html.erb
42
- - rails_generators/dry_crud/templates/app/views/crud/edit.html.erb
43
- - rails_generators/dry_crud/templates/app/views/crud/index.html.erb
44
- - rails_generators/dry_crud/templates/app/views/crud/new.html.erb
45
- - rails_generators/dry_crud/templates/app/views/crud/show.html.erb
46
- - rails_generators/dry_crud/templates/app/views/layouts/crud.html.erb
47
- - rails_generators/dry_crud/templates/app/views/shared/_labeled.html.erb
48
- - rails_generators/dry_crud/templates/INSTALL
49
- - rails_generators/dry_crud/templates/lib/crud_callbacks.rb
50
- - rails_generators/dry_crud/templates/lib/render_inheritable.rb
51
- - rails_generators/dry_crud/templates/lib/standard_form_builder.rb
52
- - rails_generators/dry_crud/templates/lib/standard_table_builder.rb
53
- - rails_generators/dry_crud/templates/public/stylesheets/crud.css
54
- - rails_generators/dry_crud/templates/test/crud_test_model.rb
55
- - rails_generators/dry_crud/templates/test/functional/crud_controller_test_helper.rb
56
- - rails_generators/dry_crud/templates/test/functional/crud_test_models_controller_test.rb
57
- - rails_generators/dry_crud/templates/test/unit/crud_helper_test.rb
58
- - rails_generators/dry_crud/templates/test/unit/render_inheritable_test.rb
59
- - rails_generators/dry_crud/templates/test/unit/standard_form_builder_test.rb
60
- - rails_generators/dry_crud/templates/test/unit/standard_helper_test.rb
61
- - rails_generators/dry_crud/templates/test/unit/standard_table_builder_test.rb
62
- - rails_generators/dry_crud/USAGE
49
+ - lib/generators/dry_crud/dry_crud_generator.rb
50
+ - lib/generators/dry_crud/templates/app/controllers/crud_controller.rb
51
+ - lib/generators/dry_crud/templates/app/controllers/render_inheritable.rb
52
+ - lib/generators/dry_crud/templates/app/helpers/crud_helper.rb
53
+ - lib/generators/dry_crud/templates/app/helpers/standard_form_builder.rb
54
+ - lib/generators/dry_crud/templates/app/helpers/standard_helper.rb
55
+ - lib/generators/dry_crud/templates/app/helpers/standard_table_builder.rb
56
+ - lib/generators/dry_crud/templates/app/views/crud/_attrs.html.erb
57
+ - lib/generators/dry_crud/templates/app/views/crud/_form.html.erb
58
+ - lib/generators/dry_crud/templates/app/views/crud/_list.html.erb
59
+ - lib/generators/dry_crud/templates/app/views/crud/edit.html.erb
60
+ - lib/generators/dry_crud/templates/app/views/crud/index.html.erb
61
+ - lib/generators/dry_crud/templates/app/views/crud/new.html.erb
62
+ - lib/generators/dry_crud/templates/app/views/crud/show.html.erb
63
+ - lib/generators/dry_crud/templates/app/views/layouts/crud.html.erb
64
+ - lib/generators/dry_crud/templates/app/views/shared/_error_messages.html.erb
65
+ - lib/generators/dry_crud/templates/app/views/shared/_labeled.html.erb
66
+ - lib/generators/dry_crud/templates/INSTALL
67
+ - lib/generators/dry_crud/templates/public/stylesheets/crud.css
68
+ - lib/generators/dry_crud/templates/test/crud_test_model.rb
69
+ - lib/generators/dry_crud/templates/test/functional/crud_controller_test_helper.rb
70
+ - lib/generators/dry_crud/templates/test/functional/crud_test_models_controller_test.rb
71
+ - lib/generators/dry_crud/templates/test/unit/crud_helper_test.rb
72
+ - lib/generators/dry_crud/templates/test/unit/render_inheritable_test.rb
73
+ - lib/generators/dry_crud/templates/test/unit/standard_form_builder_test.rb
74
+ - lib/generators/dry_crud/templates/test/unit/standard_helper_test.rb
75
+ - lib/generators/dry_crud/templates/test/unit/standard_table_builder_test.rb
76
+ - lib/generators/dry_crud/USAGE
63
77
  - test/templates/app/controllers/ajax_controller.rb
64
78
  - test/templates/app/controllers/application_controller.rb
65
79
  - test/templates/app/controllers/cities_controller.rb
@@ -97,7 +111,7 @@ rdoc_options:
97
111
  - --line-numbers
98
112
  - --inline-source
99
113
  require_paths:
100
- - rails_generators
114
+ - lib
101
115
  required_ruby_version: !ruby/object:Gem::Requirement
102
116
  none: false
103
117
  requirements:
@@ -122,6 +136,6 @@ rubyforge_project:
122
136
  rubygems_version: 1.3.7
123
137
  signing_key:
124
138
  specification_version: 3
125
- summary: Generates DRY but extendable CRUD controller, views and helpers for Rails applications
139
+ summary: Generates DRY and specifically extendable CRUD controller, views and helpers for Rails applications
126
140
  test_files: []
127
141
 
@@ -1 +0,0 @@
1
- script/generate dry_crud
@@ -1,22 +0,0 @@
1
- class DryCrudGenerator < Rails::Generator::Base
2
-
3
- def manifest
4
- record do |m|
5
- # copy everything in template subfolders
6
- Dir.chdir(File.join(File.dirname(__FILE__), 'templates')) do
7
- Dir.glob("*/**/*").each do |f|
8
- if File.directory?(f)
9
- m.directory f
10
- else
11
- m.file f, f
12
- end
13
- end
14
- end
15
-
16
- #m.template src, dst
17
-
18
- m.readme "INSTALL"
19
- end
20
- end
21
-
22
- end
@@ -1,5 +0,0 @@
1
- <div class="labeled">
2
- <%-# presence is Rails 2.3.8 for label.present? ? label : StandardHelper::EMPTY_STRING -%>
3
- <div class="caption"><%= label.presence || StandardHelper::EMPTY_STRING %></div>
4
- <div class="value"><%= content.presence || StandardHelper::EMPTY_STRING %></div>
5
- </div>
@@ -1,55 +0,0 @@
1
- # Defines before and after callback hooks for render, create, update, save and destroy.
2
- # When to execute the callbacks is in the responsibility of the clients of this module.
3
- #
4
- # The following callbacks may be defined:
5
- # * before_create
6
- # * after_create
7
- # * before_update
8
- # * after_update
9
- # * before_save
10
- # * after_save
11
- # * before_destroy
12
- # * after_destroy
13
- # * before_render_index
14
- # * before_render_show
15
- # * before_render_new
16
- # * before_render_edit
17
- #
18
- module CrudCallbacks
19
-
20
- def self.included(base)
21
- base.send :include, ActiveSupport::Callbacks
22
-
23
- base.define_callbacks :before_create, :after_create,
24
- :before_update, :after_update,
25
- :before_save, :after_save,
26
- :before_destroy, :after_destroy,
27
- :before_render_index,
28
- :before_render_show,
29
- :before_render_new,
30
- :before_render_edit
31
- end
32
-
33
- protected
34
-
35
- # Helper method the run the given block in between the before and after
36
- # callbacks of the given kind.
37
- def with_callbacks(kind)
38
- return false if callbacks("before_#{kind}".to_sym) == false
39
- if result = yield
40
- callbacks("after_#{kind}".to_sym)
41
- end
42
- result
43
- end
44
-
45
- def render_callbacks(action)
46
- run_callbacks("before_render_#{action}".to_sym) do |result, object|
47
- result == false || object.performed?
48
- end
49
- end
50
-
51
- def callbacks(kind)
52
- run_callbacks(kind) { |result, object| false == result }
53
- end
54
-
55
- end
@@ -1,118 +0,0 @@
1
- # Allows one to render inheritable views and partials.
2
- # If no view file is found for the current controller, the corresponding file
3
- # is looked up in its superclass hierarchy. This module must only be
4
- # included in the root controller of the desired lookup hierarchy.
5
- #
6
- # By default, this module only supports direct inheritance over one level. By overriding
7
- # the method lookup_path, you may define a custom lookup path. By providing an object
8
- # for the 'with' parameter, this path may even be dynamic.
9
- module RenderInheritable
10
-
11
- protected
12
-
13
- # Add inheritable_root_path method to includer
14
- def self.included(controller_class)
15
- controller_class.send(:extend, ClassMethods)
16
-
17
- controller_class.send(:class_variable_set, :@@inheritable_root_controller, controller_class)
18
- controller_class.cattr_reader :inheritable_root_controller
19
-
20
- controller_class.helper ViewHelper
21
- controller_class.helper_method :inheritable_partial_options
22
- end
23
-
24
- # Method from ActionController::Base overriden, so render_inheritable will be
25
- # called if the action does not call render explicitly.
26
- def default_render
27
- render_inheritable :action => action_name
28
- end
29
-
30
- # Renders an action or a partial considering the lookup path. Templates
31
- # specified in the :action or :partial options are looked up and the most
32
- # specific one found will get rendered. The options are directly passed to
33
- # the original render method.
34
- def render_inheritable(options)
35
- if options[:action]
36
- inheritable_template_options(options)
37
- elsif options[:partial]
38
- inheritable_partial_options(options)
39
- end
40
- render options
41
- end
42
-
43
- # Replaces the :template option with the file found in the lookup.
44
- def inheritable_template_options(options)
45
- file = options.delete(:action)
46
- inheritable_file_options(options, :template, file)
47
- end
48
-
49
- # Replaces the :partial option with the file found in the lookup.
50
- def inheritable_partial_options(options)
51
- inheritable_file_options(options, :partial, options[:partial])
52
- end
53
-
54
- def inheritable_file_options(options, key, file) #:nodoc:
55
- with = options.delete(:with)
56
- filename = (key == :partial) ? "_#{file}" : file
57
- folder = self.class.find_inheritable_file(filename, default_template_format, with)
58
- options[key] = folder.present? ? "#{folder}/#{file}" : file
59
- end
60
-
61
- module ClassMethods
62
- # Performs a lookup for the given filename and returns the most specific
63
- # folder that contains the file.
64
- def find_inheritable_file(filename, format = :html, with = nil)
65
- inheritable_cache[format.to_sym][filename][with] ||= find_inheritable_artifact(with) do |folder|
66
- view_paths.find_template("#{folder}/#{filename}", format).present? rescue false
67
- end
68
- end
69
-
70
- # Performs a lookup for a controller and returns the name of the most specific one found.
71
- # This method is primarly usefull when given a 'with' argument, that is used
72
- # in a custom lookup_path.
73
- def inheritable_controller(with = nil)
74
- c = find_inheritable_artifact(with) do |folder|
75
- ActionController::Routing.possible_controllers.any? { |c| c == folder }
76
- end
77
- c || inheritable_root_controller.controller_path
78
- end
79
-
80
- # Runs through the lookup path and yields each folder to the passed block.
81
- # If the block returns true, this folder is returned and no further lookup
82
- # happens. If no folder is found, the nil is returned.
83
- def find_inheritable_artifact(with = nil)
84
- lookup_path(with).each { |folder| return folder if yield(folder) }
85
- nil
86
- end
87
-
88
- # An array of controller names / folders, ordered from most specific to most general.
89
- # May be dynamic dependening on the passed 'with' argument.
90
- # You may override this method in an own controller to customize the lookup path.
91
- def lookup_path(with = nil)
92
- inheritance_lookup_path
93
- end
94
-
95
- # The inheritance path of controllers that is used as default lookup path.
96
- def inheritance_lookup_path
97
- path = [self]
98
- until path.last == inheritable_root_controller
99
- path << path.last.superclass
100
- end
101
- path.collect(&:controller_path)
102
- end
103
-
104
- def inheritable_cache #:nodoc:
105
- @inheritable_cache ||= Hash.new {|h, k| h[k] = Hash.new {|h, k| h[k] = Hash.new } }
106
- end
107
- end
108
-
109
- module ViewHelper
110
- # Because ActionView has a different :render method than ActionController,
111
- # this method provides an entry point to use render_inheritable from views.
112
- def render_inheritable(options)
113
- inheritable_partial_options(options) if options[:partial]
114
- render options
115
- end
116
- end
117
-
118
- end