formy 0.0.1

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,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in formy.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/formy.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "formy/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "formy"
7
+ s.version = Formy::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Sam Taylor"]
10
+ s.email = ["sjltaylor@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Create helpful forms}
13
+ #s.description = %q{TODO: Write a gem description}
14
+
15
+ s.rubyforge_project = "formy"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ end
@@ -0,0 +1,98 @@
1
+ module Formy
2
+ class FormBuilder < ActionView::Helpers::FormBuilder
3
+
4
+ def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
5
+ @template.content_tag name, content_or_options_with_block, options, &block
6
+ end
7
+
8
+ def tag(name, options = nil, open = false, escape = true)
9
+ @template.tag name, options, open, escape
10
+ end
11
+
12
+ def description attribute, options={}
13
+ content_tag :div, :class => ['formy-input-description', attribute] do
14
+ options.delete :description
15
+ end
16
+ end
17
+
18
+ def errors attribute, options={}
19
+ content_tag :div, :class => ['formy-error-flash', attribute] do
20
+ @object.errors[attribute].join ", "
21
+ end
22
+ end
23
+
24
+ def formy_text_input attribute, options={}
25
+ content_tag :div, :class => ['formy-input', attribute] do
26
+
27
+ lbl = self.label attribute
28
+ desc = description attribute, options
29
+ input = text_field attribute, options
30
+ errors = self.errors attribute, options
31
+
32
+ lbl + desc + input + errors
33
+ end
34
+ end
35
+
36
+ def formy_email_input attribute, options={}
37
+ content_tag :div, :class => ['formy-input', attribute] do
38
+
39
+ lbl = self.label attribute
40
+ desc = description attribute, options
41
+ input = email_field attribute
42
+ errors = self.errors attribute, options
43
+
44
+ lbl + desc + input + errors
45
+ end
46
+ end
47
+
48
+ def formy_password_input attribute, options={}
49
+ content_tag :div, :class => ['formy-input', attribute] do
50
+
51
+ lbl = self.label attribute
52
+ desc = description attribute, options
53
+ input = password_field attribute, options
54
+ errors = self.errors attribute, options
55
+
56
+ lbl + desc + input + errors
57
+ end
58
+ end
59
+
60
+
61
+ # add cancel and/or submit buttons to the form.
62
+ # example usage:
63
+ # formy_buttons :cancel => true, :submit => true
64
+ # creates buttons with the default labels 'cancel' and 'submit'
65
+ # to change the label use like this:
66
+ # formy_buttons :cancel => 'abandon', :submit => 'send'
67
+ def formy_buttons buttons={}
68
+
69
+ form_error_flash = content_tag :div, :class => ['formy-error-flash'] do
70
+ @object.errors[:base].join ", "
71
+ end
72
+
73
+ ajax_loader_content = tag :img, :class => ['formy-ajax-loader'], :src => '/images/ajax-loader.gif', :alt => 'loading...'
74
+
75
+ # replace the button entry in the hash with appropriate html
76
+ [:cancel, :submit].each do |button|
77
+
78
+ content = buttons[button]
79
+
80
+ if content.blank?
81
+ buttons[button] = ''
82
+ else
83
+ # use the symbol name if true is passed, otherwise use what was specified
84
+ button_html = content.class==TrueClass ? button.to_s : content
85
+
86
+ # replaces the hash entry with html content_tag
87
+ buttons[button] = content_tag :span, :class => ["formy-button", button.to_s] do
88
+ button_html
89
+ end
90
+ end
91
+ end
92
+
93
+ buttons_content = content_tag :div, :class => ['formy-buttons'] do
94
+ form_error_flash + ajax_loader_content + buttons[:cancel] + buttons[:submit]
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,8 @@
1
+ module Formy
2
+ module Helper
3
+ def formy_for attribute, options={}, &block
4
+ options[:builder] = FormBuilder
5
+ form_for attribute, options, &block
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Formy
2
+ VERSION = "0.0.1"
3
+ end
data/lib/formy.rb ADDED
@@ -0,0 +1,5 @@
1
+ Dir["#{File.dirname __FILE__}/formy/*.rb"].each {|file| require "#{file}" }
2
+
3
+ module Formy
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: formy
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Sam Taylor
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-12 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description:
18
+ email:
19
+ - sjltaylor@gmail.com
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - .gitignore
28
+ - Gemfile
29
+ - Rakefile
30
+ - formy.gemspec
31
+ - lib/formy.rb
32
+ - lib/formy/form_builder.rb
33
+ - lib/formy/formy_helper.rb
34
+ - lib/formy/version.rb
35
+ has_rdoc: true
36
+ homepage: ""
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ requirements: []
57
+
58
+ rubyforge_project: formy
59
+ rubygems_version: 1.5.0
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Create helpful forms
63
+ test_files: []
64
+