padrino-form-errors 0.0.3

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.
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ *.gem
23
+ .yardoc
24
+ doc
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kriss 'nu7hatch' Kowalik
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,60 @@
1
+ = Padrino form errors helper
2
+
3
+ This plugin is overriding standard +error_messages_for+ and +error_message_on+.
4
+ Now you can decide in which template will be displayed your validation messages.
5
+
6
+ == Installation
7
+
8
+ Install plugin via rubygems:
9
+
10
+ gem install padrino-form-errors
11
+
12
+ And run generator:
13
+
14
+ padrino-gen form_errors
15
+
16
+ In your +app/views/shared+ you'll find two new partials:
17
+
18
+ +_error_messages.html.*+ :: template for error_messages_for
19
+ +_error_message.html.*+ :: template for error_message_on
20
+
21
+ == Overriding templates
22
+
23
+ You can freely modify views listed above. In +_error_messages+ you can use
24
+ following local variables:
25
+
26
+ +object+ :: main object passed in arguments (or associated with form)
27
+ +errors+ :: merged list with errors
28
+
29
+ In +_error_message+ there are following local variables:
30
+
31
+ +object+ :: object passed in arguments (or associated with form)
32
+ +field+ :: field name passed in arguments
33
+ +error+ :: error message
34
+
35
+ == Usage
36
+
37
+ You don't have to learn nothing new about how to use functionalities provided
38
+ by this plugin. Like I said it overrides standard helpers, so when you will
39
+ write...
40
+
41
+ - form_for @user, url(:users_create) do |f|
42
+ = f.error_messages
43
+ -# ...
44
+
45
+ ...then error messages for this form will be displayed using from your shared
46
+ templates. The same is with +error_messages_for+ and +error_message_on+.
47
+
48
+ == Note on Patches/Pull Requests
49
+
50
+ * Fork the project.
51
+ * Make your feature addition or bug fix.
52
+ * Add tests for it. This is important so I don't break it in a
53
+ future version unintentionally.
54
+ * Commit, do not mess with rakefile, version, or history.
55
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
56
+ * Send me a pull request. Bonus points for topic branches.
57
+
58
+ == Copyright
59
+
60
+ Copyright (c) 2010 Kriss 'nu7hatch' Kowalik. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "padrino-form-errors"
8
+ gem.summary = %Q{Form validation errors helper for Padrino}
9
+ gem.description = %Q{Validation errors explanation done in good way for Padrino framework.}
10
+ gem.email = "kriss.kowalik@gmail.com"
11
+ gem.homepage = "http://github.com/nu7hatch/padrino-form-errors"
12
+ gem.authors = ["Kriss 'nu7hatch' Kowalik"]
13
+ gem.add_dependency "padrino", ">= 0.9.14"
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "Padrino errors explanation plugin #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.3
@@ -0,0 +1,34 @@
1
+ require 'padrino-core'
2
+ require 'padrino-gen'
3
+ require 'padrino-helpers'
4
+
5
+ FileSet.glob_require('padrino-form-errors/*.rb', __FILE__)
6
+ FileSet.glob_require('padrino-form-errors/helpers/*.rb', __FILE__)
7
+
8
+ module Padrino
9
+ ##
10
+ # This component is used to display flexible error messages in your forms.
11
+ #
12
+ module FormErrors
13
+ ##
14
+ # Method used by Padrino::Application when we register the extension
15
+ #
16
+ class << self
17
+ def registered(app)
18
+ app.helpers Padrino::FormErrors::Helpers::FormHelpers
19
+ end
20
+ alias :included :registered
21
+ end
22
+ end
23
+ end
24
+
25
+ ##
26
+ # Load our Padrino::Responders locales
27
+ #
28
+ I18n.load_path += Dir["#{File.dirname(__FILE__)}/padrino-form-errors/locale/**/*.yml"]
29
+
30
+ ##
31
+ # Now we need to add form explanations views generators to padrino-gen
32
+ #
33
+ Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/padrino-form-errors/generators/{errors_explanation}.rb']
34
+
@@ -0,0 +1,32 @@
1
+ module Padrino
2
+ module FormErrors
3
+ module Generators
4
+ class Defaults < Thor::Group
5
+ # Add this generator to our padrino-gen
6
+ Padrino::Generators.add_generator(:form_errors, self)
7
+
8
+ # Define the source template root
9
+ def self.source_root; File.expand_path(File.dirname(__FILE__)); end
10
+ def self.banner; "padrino-gen form_errors"; end
11
+
12
+ # Include related modules
13
+ include Thor::Actions
14
+ include Padrino::Generators::Actions
15
+
16
+ desc "Description:\n\n\tpadrino-gen form_errors"
17
+
18
+ # Create default views.
19
+ def create_views
20
+ ext = fetch_component_choice(:renderer)
21
+ self.destination_root = options[:root]
22
+ if in_app_root?
23
+ template "templates/#{ext}/_error_messages.#{ext}.tt", destination_root("/app/views/shared/_error_messages.html.#{ext}")
24
+ template "templates/#{ext}/_error_message.#{ext}.tt", destination_root("/app/views/shared/_error_message.html.#{ext}")
25
+ else
26
+ say "You are not at the root of a Padrino application! (config/boot.rb not found)"
27
+ end
28
+ end
29
+ end # Defaults
30
+ end # Generators
31
+ end # FormErrors
32
+ end # Padrino
@@ -0,0 +1,3 @@
1
+ <div class="inline-error">
2
+ <%= error.to_s %>
3
+ </div>
@@ -0,0 +1,8 @@
1
+ <div class="errors-explanation">
2
+ <h3><%= object.class.to_s.underscore %> couldn not be saved</h3>
3
+ <ul>
4
+ <%- object.errors.full_messages.each do |msg| %>
5
+ <li><%= msg %></li>
6
+ <%- end %>
7
+ </ul>
8
+ </div>
@@ -0,0 +1 @@
1
+ .inline-error= error.to_s
@@ -0,0 +1,5 @@
1
+ .errors-explanation
2
+ %h3 #{object.class.to_s.underscore} couldn not be saved
3
+ %ul
4
+ - object.errors.full_messages.each do |msg|
5
+ %li= msg
@@ -0,0 +1,51 @@
1
+ module Padrino
2
+ module FormErrors
3
+ module Helpers
4
+ module FormHelpers
5
+ ##
6
+ # It displays validation errors for given object. Here is an HAML example:
7
+ #
8
+ # ==== Examples
9
+ #
10
+ # - form_tag url(:users) do
11
+ # = error_messages_for(@user)
12
+ # -# ...
13
+ #
14
+ def error_messages_for(*objects)
15
+ objects.map! do |object|
16
+ if object.is_a? Symbol
17
+ instance_variable_get("@#{object}")
18
+ elsif object.respond_to? :object
19
+ object = object.object
20
+ else
21
+ object
22
+ end
23
+ end
24
+ errors = objects.map {|object| object.errors }.flatten
25
+ if errors.size > 0
26
+ partial "shared/error_messages", :locals => { :object => objects.first, :errors => errors }
27
+ end
28
+ end
29
+
30
+ ##
31
+ # It displays inline error for single field.
32
+ #
33
+ # ==== Examples
34
+ #
35
+ # - form_tag url(:sessions_login) do
36
+ # = label "Login", :for => :login
37
+ # = text_field_tag :login
38
+ # = error_messages_on(@session, :login)
39
+ # -# ...
40
+ #
41
+ def error_messages_on(object, field)
42
+ object = instance_variable_get("@#{object}") if object.is_a?(Symbol)
43
+ error = object.errors[field] rescue nil
44
+ if error
45
+ partial "shared/error_message", :locals => { :object => object, :field => field, :error => error }
46
+ end
47
+ end
48
+ end # FormHelpers
49
+ end # Helpers
50
+ end # FormErrors
51
+ end # Padrino
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: padrino-form-errors
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Kriss 'nu7hatch' Kowalik
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-06 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: padrino
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 39
30
+ segments:
31
+ - 0
32
+ - 9
33
+ - 14
34
+ version: 0.9.14
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Validation errors explanation done in good way for Padrino framework.
38
+ email: kriss.kowalik@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.rdoc
46
+ files:
47
+ - .gitignore
48
+ - LICENSE
49
+ - README.rdoc
50
+ - Rakefile
51
+ - VERSION
52
+ - lib/padrino-form-errors.rb
53
+ - lib/padrino-form-errors/generators/defaults.rb
54
+ - lib/padrino-form-errors/generators/templates/erb/_error_message.erb.tt
55
+ - lib/padrino-form-errors/generators/templates/erb/_error_messages.erb.tt
56
+ - lib/padrino-form-errors/generators/templates/haml/_error_message.haml.tt
57
+ - lib/padrino-form-errors/generators/templates/haml/_error_messages.haml.tt
58
+ - lib/padrino-form-errors/helpers/form_helpers.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/nu7hatch/padrino-form-errors
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.7
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Form validation errors helper for Padrino
93
+ test_files: []
94
+