Module: Errors2Html
- Defined in:
- lib/rails_errors2html.rb,
lib/rails_errors2html/_lib.rb
Defined Under Namespace
Modules: Mixin
Constant Summary collapse
- Version =
'1.5.1'
Class Method Summary collapse
- .dependencies ⇒ Object
- .flatten(hashlike) ⇒ Object
- .libdir(*args, &block) ⇒ Object
- .load(*libs) ⇒ Object
- .load_dependencies! ⇒ Object
- .summary ⇒ Object
- .to_html(*args) ⇒ Object
- .version ⇒ Object
Class Method Details
.dependencies ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/rails_errors2html/_lib.rb', line 13 def dependencies { 'fattr' => [ 'fattr' , ' ~> 2' ], 'map' => [ 'map' , ' ~> 6' ], 'rails_view' => [ 'rails_view' , ' ~> 1' ] } end |
.flatten(hashlike) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rails_errors2html.rb', line 53 def Errors2Html.flatten(hashlike) case hashlike when Map hash = Hash.new hashlike.depth_first_each do |key, value| index = key.pop if key.last.is_a?(Integer) (hash[key] ||= []).push(value) end hash else hashlike.respond_to?(:to_hash) ? hashlike.to_hash : hashlike end end |
.libdir(*args, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rails_errors2html/_lib.rb', line 34 def libdir(*args, &block) @libdir ||= File.dirname(File.(__FILE__).sub(/\.rb$/,'')) args.empty? ? @libdir : File.join(@libdir, *args) ensure if block begin $LOAD_PATH.unshift(@libdir) block.call() ensure $LOAD_PATH.shift() end end end |
.load(*libs) ⇒ Object
48 49 50 51 |
# File 'lib/rails_errors2html/_lib.rb', line 48 def load(*libs) libs = libs.join(' ').scan(/[^\s+]+/) libdir{ libs.each{|lib| Kernel.load(lib) } } end |
.load_dependencies! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rails_errors2html/_lib.rb', line 21 def load_dependencies! begin require 'rubygems' rescue LoadError nil end dependencies.each do |lib, dependency| gem(*dependency) if defined?(gem) require(lib) end end |
.summary ⇒ Object
9 10 11 |
# File 'lib/rails_errors2html/_lib.rb', line 9 def summary "tiny, KISS html rendering of active_model errors" end |
.to_html(*args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rails_errors2html.rb', line 5 def Errors2Html.to_html(*args) if args.size == 1 case args.first when Array, String, Symbol = Array(args.first) args = [{:base => }] end end args.flatten! args.compact! at_least_one_error = false errors = Map.new errors[:global] = [] errors[:fields] = {} args.each do |e| flatten(e).each do |key, | Array().each do || at_least_one_error = true = .to_s.html_safe if Array(key).join =~ /\A(?:[*]|base)\Z/iomx errors.global.push().uniq! else (errors.fields[key] ||= []).push().uniq! end end end end return "" unless at_least_one_error locals = { :errors => errors, :global_errors => errors.global, :fields_errors => errors.fields } if template View.render(:template => template, :locals => locals, :layout => false) else View.render(:inline => inline, :locals => locals, :layout => false) end end |
.version ⇒ Object
5 6 7 |
# File 'lib/rails_errors2html/_lib.rb', line 5 def version Version end |