drogus-merb-sexy-forms 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/LICENSE +20 -0
- data/README +6 -0
- data/Rakefile +71 -0
- data/TODO +1 -0
- data/assets/images/sexy_forms/fieldbg.gif +0 -0
- data/assets/stylesheets/sexy_forms.css +56 -0
- data/lib/merb-sexy-forms/builder.rb +137 -0
- data/lib/merb-sexy-forms/form.rb +20 -0
- data/lib/merb-sexy-forms/merbtasks.rb +11 -0
- data/lib/merb-sexy-forms.rb +20 -0
- data/spec/fixture/app/controllers/application.rb +2 -0
- data/spec/fixture/app/controllers/sexy_form.rb +2 -0
- data/spec/fixture/app/controllers/specs_controller.rb +11 -0
- data/spec/fixture/app/views/sexy_form_specs/label_choice_class.html.erb +4 -0
- data/spec/fixture/app/views/sexy_form_specs/with_labels.html.erb +3 -0
- data/spec/fixture/config/environments/development.rb +6 -0
- data/spec/fixture/config/environments/production.rb +5 -0
- data/spec/fixture/config/environments/test.rb +6 -0
- data/spec/fixture/config/init.rb.rb +46 -0
- data/spec/fixture/config/rack.rb +11 -0
- data/spec/fixture/config/router.rb +38 -0
- data/spec/merb-sexy-forms-form_spec.rb +29 -0
- data/spec/merb-sexy-forms_spec.rb +7 -0
- data/spec/merb_test.log +1 -0
- data/spec/spec_helper.rb +153 -0
- metadata +100 -0
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2008 Piotr Sarnacki
|
|
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
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake/gempackagetask'
|
|
3
|
+
|
|
4
|
+
require 'merb-core'
|
|
5
|
+
require 'merb-core/tasks/merb'
|
|
6
|
+
|
|
7
|
+
require 'date'
|
|
8
|
+
require "spec/rake/spectask"
|
|
9
|
+
|
|
10
|
+
require 'lib/merb-sexy-forms/merbtasks.rb'
|
|
11
|
+
|
|
12
|
+
GEM_NAME = "merb-sexy-forms"
|
|
13
|
+
GEM_VERSION = "0.0.3"
|
|
14
|
+
AUTHOR = "Piotr Sarnacki"
|
|
15
|
+
EMAIL = "drogus@gmail.com"
|
|
16
|
+
HOMEPAGE = ""
|
|
17
|
+
SUMMARY = "Merb plugin that provides extended builder for forms"
|
|
18
|
+
|
|
19
|
+
spec = Gem::Specification.new do |s|
|
|
20
|
+
s.rubyforge_project = 'merb'
|
|
21
|
+
s.name = GEM_NAME
|
|
22
|
+
s.version = GEM_VERSION
|
|
23
|
+
s.platform = Gem::Platform::RUBY
|
|
24
|
+
s.has_rdoc = true
|
|
25
|
+
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
|
26
|
+
s.summary = SUMMARY
|
|
27
|
+
s.description = s.summary
|
|
28
|
+
s.author = AUTHOR
|
|
29
|
+
s.email = EMAIL
|
|
30
|
+
s.homepage = HOMEPAGE
|
|
31
|
+
s.add_dependency('merb', '>= 1.0.6.1')
|
|
32
|
+
s.require_path = 'lib'
|
|
33
|
+
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec,assets}/**/*")
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
|
38
|
+
pkg.gem_spec = spec
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
desc "install the plugin as a gem"
|
|
42
|
+
task :install do
|
|
43
|
+
Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
desc "Uninstall the gem"
|
|
47
|
+
task :uninstall do
|
|
48
|
+
Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
desc "Create a gemspec file"
|
|
52
|
+
task :gemspec do
|
|
53
|
+
File.open("#{GEM_NAME}.gemspec", "w") do |file|
|
|
54
|
+
file.puts spec.to_ruby
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
desc "Run all examples (or a specific spec with TASK=xxxx)"
|
|
59
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
|
60
|
+
t.spec_opts = ["-cfs"]
|
|
61
|
+
t.spec_files = begin
|
|
62
|
+
if ENV["TASK"]
|
|
63
|
+
ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
|
|
64
|
+
else
|
|
65
|
+
FileList['spec/**/*_spec.rb']
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
desc 'Default: run spec examples'
|
|
71
|
+
task :default => 'spec'
|
|
Binary file
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* This file can be overwriten by rake task - if you want to customize
|
|
2
|
+
styles try to overwrite selectors them in another file or make new
|
|
3
|
+
stylesheet
|
|
4
|
+
*/
|
|
5
|
+
form.sexy ul {
|
|
6
|
+
padding: 0px;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
form.sexy label.main {
|
|
10
|
+
line-height: 1.5em;
|
|
11
|
+
color: #000;
|
|
12
|
+
font-weight: bold;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
form.sexy ul li {
|
|
16
|
+
width: 97% !important;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
form.sexy li {
|
|
20
|
+
clear: both;
|
|
21
|
+
display: block;
|
|
22
|
+
margin: 0;
|
|
23
|
+
padding: 5px 5px 2px 10px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
form.sexy ul li div input[type=text], form.sexy ul li div textarea,
|
|
27
|
+
form.sexy ul li div input[type=password] {
|
|
28
|
+
width: 100%;
|
|
29
|
+
border-color:#7C7C7C #a2a2a2 #b2b2b2;
|
|
30
|
+
border-style: solid;
|
|
31
|
+
border-width: 1px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
form.sexy input[type=text], form.sexy textarea, form.sexy input[type=password] {
|
|
35
|
+
background: #FFFFFF url(/images/sexy_forms/fieldbg.gif) repeat-x scroll center top;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
form.sexy ul li div textarea {
|
|
39
|
+
height: 9em;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
form.sexy label.choice {
|
|
43
|
+
display: block;
|
|
44
|
+
line-height: 1.5em;
|
|
45
|
+
margin: -1.4em 0 0 25px;
|
|
46
|
+
padding: 0.185em 0 0.6em;
|
|
47
|
+
width: 88%;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
input.checkbox, input.radio {
|
|
51
|
+
display:block;
|
|
52
|
+
line-height: 1.5em;
|
|
53
|
+
margin:0.6em 0 0 3px;
|
|
54
|
+
width: 15px;
|
|
55
|
+
height: 15px;
|
|
56
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
module Merb::Helpers::SexyForm
|
|
2
|
+
module Builder
|
|
3
|
+
class Base < Merb::Helpers::Form::Builder::ResourcefulFormWithErrors
|
|
4
|
+
def form(attrs = {}, &blk)
|
|
5
|
+
ul_options = attrs.delete(:ul)
|
|
6
|
+
add_css_class(attrs, "sexy")
|
|
7
|
+
super(attrs) do
|
|
8
|
+
captured = @origin.capture(&blk)
|
|
9
|
+
tag(:ul, captured, ul_options)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def wrap_with_container(attrs = {}, content = "")
|
|
14
|
+
li = attrs.delete(:li)
|
|
15
|
+
container = attrs.delete(:container)
|
|
16
|
+
|
|
17
|
+
first = attrs.delete(:first)
|
|
18
|
+
method = attrs.delete(:method)
|
|
19
|
+
|
|
20
|
+
if first && (attrs[:id] || method)
|
|
21
|
+
if method
|
|
22
|
+
id = method ? "#{@name}_#{method}" : attrs[:id]
|
|
23
|
+
end
|
|
24
|
+
label_id = "#{id}_#{first[:value]}"
|
|
25
|
+
else
|
|
26
|
+
label_id = attrs[:id]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
label = attrs.delete(:label)
|
|
30
|
+
if label && !label.is_a?(Hash)
|
|
31
|
+
label = {:label => {:title => label}}
|
|
32
|
+
end
|
|
33
|
+
if label.is_a?(Hash)
|
|
34
|
+
label[:label].merge!({:class => "main", :for => label_id})
|
|
35
|
+
end
|
|
36
|
+
label = label(label)
|
|
37
|
+
|
|
38
|
+
if container == false
|
|
39
|
+
content = label + content
|
|
40
|
+
else
|
|
41
|
+
content = label + tag(:div, content, container)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
if li == false
|
|
45
|
+
content
|
|
46
|
+
else
|
|
47
|
+
li = li || {}
|
|
48
|
+
li.merge!(:id => "#{attrs[:id]}_container") if attrs[:id] and li[:id].blank?
|
|
49
|
+
tag(:li, content, li)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
%w(text password file).each do |kind|
|
|
54
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
55
|
+
def unbound_#{kind}_field(attrs = {})
|
|
56
|
+
label = attrs.delete(:label)
|
|
57
|
+
wrap_with_container(attrs.merge(:label => label), super(clean_args!(attrs)))
|
|
58
|
+
end
|
|
59
|
+
RUBY
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def unbound_check_box(attrs = {})
|
|
63
|
+
update_label_options(attrs, "radio")
|
|
64
|
+
wrap_with_container(attrs.merge(:label => nil),
|
|
65
|
+
super(clean_args!(attrs)))
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def unbound_radio_button(attrs = {})
|
|
69
|
+
update_label_options(attrs, "radio")
|
|
70
|
+
wrap_with_container(attrs.merge(:label => nil),
|
|
71
|
+
super(clean_args!(attrs)))
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def bound_radio_group(method, arr, global_attrs = {})
|
|
75
|
+
first = arr.first
|
|
76
|
+
wrap_with_container(global_attrs.merge(:first => first, :method => method), super(method, arr))
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def unbound_radio_group(arr, global_attrs = {})
|
|
80
|
+
wrap_with_container(global_attrs, super(arr))
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def unbound_select(attrs = {})
|
|
84
|
+
wrap_with_container(attrs, super(clean_args!(attrs)))
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def unbound_text_area(contents, attrs = {})
|
|
88
|
+
label = attrs.delete(:label)
|
|
89
|
+
wrap_with_container(attrs.merge(:label => label), super(clean_args!(attrs)))
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def button(contents, attrs = {})
|
|
93
|
+
wrap_with_container(attrs, super(contents, clean_args!(attrs)))
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def submit(value, attrs = {})
|
|
97
|
+
wrap_with_container(attrs, super(value, clean_args!(attrs)))
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
private
|
|
101
|
+
def update_label_options(attrs, type)
|
|
102
|
+
case type
|
|
103
|
+
when "radio", "checkbox"
|
|
104
|
+
if attrs[:label] && !attrs[:label].is_a?(Hash)
|
|
105
|
+
attrs[:label] = {:title => attrs.delete(:label)}
|
|
106
|
+
add_css_class(attrs[:label], "choice")
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def clean_args!(attrs)
|
|
112
|
+
new_attrs = attrs.dup
|
|
113
|
+
new_attrs.delete(:li)
|
|
114
|
+
new_attrs.delete(:container)
|
|
115
|
+
new_attrs
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def radio_group_item(method, attrs)
|
|
119
|
+
attrs.merge!(:checked => "checked") if attrs[:checked]
|
|
120
|
+
attrs[:li] = false
|
|
121
|
+
attrs[:container] = false
|
|
122
|
+
super
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def process_form_attrs(attrs)
|
|
126
|
+
attrs[:id] = "#{@name}" unless attrs[:id] || @name.nil?
|
|
127
|
+
|
|
128
|
+
if (@obj.respond_to?(:new_record?) && !@obj.new_record?) || (@obj.respond_to?(:new?) && !@obj.new?)
|
|
129
|
+
add_css_class(attrs, "edit")
|
|
130
|
+
else
|
|
131
|
+
add_css_class(attrs, "new")
|
|
132
|
+
end
|
|
133
|
+
super(attrs)
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Merb::Helpers::Form
|
|
2
|
+
def sexy_form(attrs = {}, &blk)
|
|
3
|
+
with_form_context_without_name(Merb::Helpers::SexyForm::Builder::Base) do
|
|
4
|
+
current_form_context.form(attrs, &blk)
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def sexy_form_for(name, attrs = {}, &blk)
|
|
9
|
+
with_form_context(name, Merb::Helpers::SexyForm::Builder::Base) do
|
|
10
|
+
current_form_context.form(attrs, &blk)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def with_form_context_without_name(builder)
|
|
15
|
+
form_contexts.push((builder || self._default_builder).new(nil, nil, self))
|
|
16
|
+
ret = yield
|
|
17
|
+
form_contexts.pop
|
|
18
|
+
ret
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
|
|
3
|
+
namespace :merb_sexy_forms do
|
|
4
|
+
desc "Update assets for sexy forms"
|
|
5
|
+
task :update_assets do
|
|
6
|
+
assets = File.join(File.dirname(__FILE__), "../../assets")
|
|
7
|
+
FileUtils.cp(File.join(assets, "stylesheets/sexy_forms.css"), "public/stylesheets/")
|
|
8
|
+
FileUtils.mkdir_p("public/images/sexy_forms")
|
|
9
|
+
FileUtils.cp(File.join(assets, "images/sexy_forms/fieldbg.gif"), "public/images/sexy_forms/")
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# make sure we're running inside Merb
|
|
2
|
+
if defined?(Merb::Plugins)
|
|
3
|
+
|
|
4
|
+
# Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
|
|
5
|
+
Merb::Plugins.config[:merb_sexy_forms] = {
|
|
6
|
+
:chickens => false
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
Merb::BootLoader.before_app_loads do
|
|
10
|
+
# require code that must be loaded before the application
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
Merb::BootLoader.after_app_loads do
|
|
14
|
+
dir = File.dirname(__FILE__) / 'merb-sexy-forms'
|
|
15
|
+
require dir + '/builder'
|
|
16
|
+
require dir + '/form'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
Merb::Plugins.add_rakefiles "merb-sexy-forms/merbtasks"
|
|
20
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Helpers are tested going through the full stack.
|
|
2
|
+
# to keep things isolated each helper has its own controller subclass
|
|
3
|
+
# if you are working on a new helper, please consider creating
|
|
4
|
+
# a new spec controller subclass
|
|
5
|
+
#
|
|
6
|
+
# Remember that your helper spec views
|
|
7
|
+
# will be located in a folder named after the controller you use
|
|
8
|
+
|
|
9
|
+
class SpecController < Merb::Controller
|
|
10
|
+
layout nil
|
|
11
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Make the app's "gems" directory a place where gems are loaded from
|
|
2
|
+
Gem.clear_paths
|
|
3
|
+
Gem.path.unshift(Merb.root / "gems")
|
|
4
|
+
|
|
5
|
+
# Make the app's "lib" directory a place where ruby files get "require"d from
|
|
6
|
+
$LOAD_PATH.unshift(Merb.root / "lib")
|
|
7
|
+
|
|
8
|
+
Merb::Config.use { |c|
|
|
9
|
+
c[:session_store] = 'cookie'
|
|
10
|
+
c[:session_secret_key] = "2c24532b38b8c46d8acf1b5ed71bdd5426dadd9b"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
### Merb doesn't come with database support by default. You need
|
|
14
|
+
### an ORM plugin. Install one, and uncomment one of the following lines,
|
|
15
|
+
### if you need a database.
|
|
16
|
+
|
|
17
|
+
### Uncomment for DataMapper ORM
|
|
18
|
+
# use_orm :datamapper
|
|
19
|
+
|
|
20
|
+
### Uncomment for ActiveRecord ORM
|
|
21
|
+
# use_orm :activerecord
|
|
22
|
+
|
|
23
|
+
### Uncomment for Sequel ORM
|
|
24
|
+
# use_orm :sequel
|
|
25
|
+
|
|
26
|
+
### This defines which test framework the generators will use
|
|
27
|
+
### rspec is turned on by default
|
|
28
|
+
# use_test :test_unit
|
|
29
|
+
# use_test :rspec
|
|
30
|
+
|
|
31
|
+
### Add your other dependencies here
|
|
32
|
+
|
|
33
|
+
# These are some examples of how you might specify dependencies.
|
|
34
|
+
#
|
|
35
|
+
# dependencies "RedCloth", "merb_helpers"
|
|
36
|
+
# OR
|
|
37
|
+
# dependency "RedCloth", "> 3.0"
|
|
38
|
+
# OR
|
|
39
|
+
# dependencies "RedCloth" => "> 3.0", "ruby-aes-cext" => "= 1.0"
|
|
40
|
+
dependency File.join(File.dirname(__FILE__),'..','..','..','lib','merb-sexy-forms')
|
|
41
|
+
|
|
42
|
+
Merb::BootLoader.after_app_loads do
|
|
43
|
+
### Add dependencies here that must load after the application loads:
|
|
44
|
+
|
|
45
|
+
# dependency "magic_admin" # this gem uses the app's model classes
|
|
46
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# use PathPrefix Middleware if :path_prefix is set in Merb::Config
|
|
2
|
+
if prefix = ::Merb::Config[:path_prefix]
|
|
3
|
+
use Merb::Rack::PathPrefix, prefix
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
# comment this out if you are running merb behind a load balancer
|
|
7
|
+
# that serves static files
|
|
8
|
+
use Merb::Rack::Static, Merb.dir_for(:public)
|
|
9
|
+
|
|
10
|
+
# this is our main merb application
|
|
11
|
+
run Merb::Rack::Application.new
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Merb::Router is the request routing mapper for the merb framework.
|
|
2
|
+
#
|
|
3
|
+
# You can route a specific URL to a controller / action pair:
|
|
4
|
+
#
|
|
5
|
+
# r.match("/contact").
|
|
6
|
+
# to(:controller => "info", :action => "contact")
|
|
7
|
+
#
|
|
8
|
+
# You can define placeholder parts of the url with the :symbol notation. These
|
|
9
|
+
# placeholders will be available in the params hash of your controllers. For example:
|
|
10
|
+
#
|
|
11
|
+
# r.match("/books/:book_id/:action").
|
|
12
|
+
# to(:controller => "books")
|
|
13
|
+
#
|
|
14
|
+
# Or, use placeholders in the "to" results for more complicated routing, e.g.:
|
|
15
|
+
#
|
|
16
|
+
# r.match("/admin/:module/:controller/:action/:id").
|
|
17
|
+
# to(:controller => ":module/:controller")
|
|
18
|
+
#
|
|
19
|
+
# You can also use regular expressions, deferred routes, and many other options.
|
|
20
|
+
# See merb/specs/merb/router.rb for a fairly complete usage sample.
|
|
21
|
+
|
|
22
|
+
Merb.logger.info("Compiling routes...")
|
|
23
|
+
Merb::Router.prepare do |r|
|
|
24
|
+
# RESTful routes
|
|
25
|
+
# r.resources :posts
|
|
26
|
+
resources :fake_models
|
|
27
|
+
resources :obj
|
|
28
|
+
resources :models
|
|
29
|
+
|
|
30
|
+
# This is the default route for /:controller/:action/:id
|
|
31
|
+
# This is fine for most cases. If you're heavily using resource-based
|
|
32
|
+
# routes, you may want to comment/remove this line to prevent
|
|
33
|
+
# clients from calling your create or destroy actions with a GET
|
|
34
|
+
r.default_routes
|
|
35
|
+
|
|
36
|
+
# Change this for your home page to be available at /
|
|
37
|
+
# r.match('/').to(:controller => 'whatever', :action =>'index')
|
|
38
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
Merb::Plugins.config[:helpers] = {
|
|
4
|
+
:default_builder => Merb::Helpers::Form::Builder::FormWithErrors
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
describe "form" do
|
|
8
|
+
|
|
9
|
+
before :each do
|
|
10
|
+
@c = SexyFormSpecs.new(Merb::Request.new({}))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should add labels with field nested in container" do
|
|
14
|
+
ret = @c.render(:with_labels)
|
|
15
|
+
ret.should have_selector("form ul li label")
|
|
16
|
+
ret.should have_selector("form ul li div input")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should add 'choice' class to labels for checkboxes or radio buttons" do
|
|
20
|
+
ret = @c.render(:label_choice_class)
|
|
21
|
+
ret.should have_selector("form div label[for=checkbox].choice")
|
|
22
|
+
ret.should have_selector("form div label[for=radio].choice")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should not add 'choice' class to main labels" do
|
|
26
|
+
ret = @c.render(:label_choice_class)
|
|
27
|
+
ret.should_not have_selector("form label.choice.main")
|
|
28
|
+
end
|
|
29
|
+
end
|
data/spec/merb_test.log
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Sat, 20 Dec 2008 13:41:20 GMT ~ info ~ Logfile created
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
require "rubygems"
|
|
2
|
+
require "spec"
|
|
3
|
+
require "merb-core"
|
|
4
|
+
require 'merb-helpers'
|
|
5
|
+
require File.join(File.dirname(__FILE__),"..",'lib',"merb-sexy-forms")
|
|
6
|
+
require "date"
|
|
7
|
+
require "webrat"
|
|
8
|
+
|
|
9
|
+
default_options = {
|
|
10
|
+
:environment => 'test',
|
|
11
|
+
:adapter => 'runner',
|
|
12
|
+
:merb_root => File.dirname(__FILE__) / 'fixture',
|
|
13
|
+
:log_file => File.dirname(__FILE__) / "merb_test.log"
|
|
14
|
+
}
|
|
15
|
+
options = default_options.merge($START_OPTIONS || {})
|
|
16
|
+
|
|
17
|
+
Merb.disable(:initfile)
|
|
18
|
+
Merb.start_environment(options)
|
|
19
|
+
|
|
20
|
+
def unload_merb_helpers
|
|
21
|
+
Merb.class_eval do
|
|
22
|
+
remove_const("Helpers") if defined?(Merb::Helpers)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def reload_merb_helpers
|
|
27
|
+
unload_merb_helpers
|
|
28
|
+
load(MERB_HELPERS_ROOT + "/lib/merb-helpers.rb")
|
|
29
|
+
Merb::Helpers.load
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class FakeErrors
|
|
33
|
+
|
|
34
|
+
def initialize(model)
|
|
35
|
+
@model = model
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def on(name)
|
|
39
|
+
name.to_s.include?("bad")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
class FakeColumn
|
|
45
|
+
attr_accessor :name, :type
|
|
46
|
+
|
|
47
|
+
def initialize(name, type)
|
|
48
|
+
@name, @type = name, type
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# -- Global custom matchers --
|
|
57
|
+
|
|
58
|
+
# A better +be_kind_of+ with more informative error messages.
|
|
59
|
+
#
|
|
60
|
+
# The default +be_kind_of+ just says
|
|
61
|
+
#
|
|
62
|
+
# "expected to return true but got false"
|
|
63
|
+
#
|
|
64
|
+
# This one says
|
|
65
|
+
#
|
|
66
|
+
# "expected File but got Tempfile"
|
|
67
|
+
|
|
68
|
+
module Merb
|
|
69
|
+
module Test
|
|
70
|
+
module RspecMatchers
|
|
71
|
+
class IncludeLog
|
|
72
|
+
def initialize(expected)
|
|
73
|
+
@expected = expected
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def matches?(target)
|
|
77
|
+
target.log.rewind
|
|
78
|
+
@text = target.log.read
|
|
79
|
+
@text =~ (String === @expected ? /#{Regexp.escape @expected}/ : @expected)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def failure_message
|
|
83
|
+
"expected to find `#{@expected}' in the log but got:\n" <<
|
|
84
|
+
@text.map {|s| " #{s}" }.join
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def negative_failure_message
|
|
88
|
+
"exected not to find `#{@expected}' in the log but got:\n" <<
|
|
89
|
+
@text.map {|s| " #{s}" }.join
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def description
|
|
93
|
+
"include #{@text} in the log"
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
class BeKindOf
|
|
98
|
+
def initialize(expected) # + args
|
|
99
|
+
@expected = expected
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def matches?(target)
|
|
103
|
+
@target = target
|
|
104
|
+
@target.kind_of?(@expected)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def failure_message
|
|
108
|
+
"expected #{@expected} but got #{@target.class}"
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def negative_failure_message
|
|
112
|
+
"expected #{@expected} to not be #{@target.class}"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def description
|
|
116
|
+
"be_kind_of #{@target}"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def be_kind_of(expected) # + args
|
|
121
|
+
BeKindOf.new(expected)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def include_log(expected)
|
|
125
|
+
IncludeLog.new(expected)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
module Helper
|
|
130
|
+
def running(&blk) blk; end
|
|
131
|
+
|
|
132
|
+
def executing(&blk) blk; end
|
|
133
|
+
|
|
134
|
+
def doing(&blk) blk; end
|
|
135
|
+
|
|
136
|
+
def calling(&blk) blk; end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
Spec::Runner.configure do |config|
|
|
142
|
+
config.include Merb::Test::Helper
|
|
143
|
+
config.include Merb::Test::RspecMatchers
|
|
144
|
+
config.include Merb::Test::RequestHelper
|
|
145
|
+
config.include Webrat::Matchers
|
|
146
|
+
config.include Webrat::HaveTagMatcher
|
|
147
|
+
|
|
148
|
+
def with_level(level)
|
|
149
|
+
Merb.logger = Merb::Logger.new(StringIO.new, level)
|
|
150
|
+
yield
|
|
151
|
+
Merb.logger
|
|
152
|
+
end
|
|
153
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: drogus-merb-sexy-forms
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.3
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Piotr Sarnacki
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2008-12-20 00:00:00 -08:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: merb
|
|
17
|
+
version_requirement:
|
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
19
|
+
requirements:
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 1.0.6.1
|
|
23
|
+
version:
|
|
24
|
+
description: Merb plugin that provides extended builder for forms
|
|
25
|
+
email: drogus@gmail.com
|
|
26
|
+
executables: []
|
|
27
|
+
|
|
28
|
+
extensions: []
|
|
29
|
+
|
|
30
|
+
extra_rdoc_files:
|
|
31
|
+
- README
|
|
32
|
+
- LICENSE
|
|
33
|
+
- TODO
|
|
34
|
+
files:
|
|
35
|
+
- LICENSE
|
|
36
|
+
- README
|
|
37
|
+
- Rakefile
|
|
38
|
+
- TODO
|
|
39
|
+
- lib/merb-sexy-forms.rb
|
|
40
|
+
- lib/merb-sexy-forms
|
|
41
|
+
- lib/merb-sexy-forms/builder.rb
|
|
42
|
+
- lib/merb-sexy-forms/merbtasks.rb
|
|
43
|
+
- lib/merb-sexy-forms/form.rb
|
|
44
|
+
- spec/fixture
|
|
45
|
+
- spec/fixture/app
|
|
46
|
+
- spec/fixture/app/controllers
|
|
47
|
+
- spec/fixture/app/controllers/application.rb
|
|
48
|
+
- spec/fixture/app/controllers/sexy_form.rb
|
|
49
|
+
- spec/fixture/app/controllers/specs_controller.rb
|
|
50
|
+
- spec/fixture/app/views
|
|
51
|
+
- spec/fixture/app/views/sexy_form_specs
|
|
52
|
+
- spec/fixture/app/views/sexy_form_specs/label_choice_class.html.erb
|
|
53
|
+
- spec/fixture/app/views/sexy_form_specs/with_labels.html.erb
|
|
54
|
+
- spec/fixture/config
|
|
55
|
+
- spec/fixture/config/init.rb.rb
|
|
56
|
+
- spec/fixture/config/environments
|
|
57
|
+
- spec/fixture/config/environments/development.rb
|
|
58
|
+
- spec/fixture/config/environments/production.rb
|
|
59
|
+
- spec/fixture/config/environments/test.rb
|
|
60
|
+
- spec/fixture/config/rack.rb
|
|
61
|
+
- spec/fixture/config/router.rb
|
|
62
|
+
- spec/merb_test.log
|
|
63
|
+
- spec/spec_helper.rb
|
|
64
|
+
- spec/merb-sexy-forms_spec.rb
|
|
65
|
+
- spec/merb-sexy-forms-form_spec.rb
|
|
66
|
+
- spec/merb.main.pid
|
|
67
|
+
- assets/stylesheets
|
|
68
|
+
- assets/stylesheets/sexy_forms.css
|
|
69
|
+
- assets/javascripts
|
|
70
|
+
- assets/images
|
|
71
|
+
- assets/images/sexy_forms
|
|
72
|
+
- assets/images/sexy_forms/fieldbg.gif
|
|
73
|
+
has_rdoc: true
|
|
74
|
+
homepage: ""
|
|
75
|
+
post_install_message:
|
|
76
|
+
rdoc_options: []
|
|
77
|
+
|
|
78
|
+
require_paths:
|
|
79
|
+
- lib
|
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: "0"
|
|
85
|
+
version:
|
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: "0"
|
|
91
|
+
version:
|
|
92
|
+
requirements: []
|
|
93
|
+
|
|
94
|
+
rubyforge_project: merb
|
|
95
|
+
rubygems_version: 1.2.0
|
|
96
|
+
signing_key:
|
|
97
|
+
specification_version: 2
|
|
98
|
+
summary: Merb plugin that provides extended builder for forms
|
|
99
|
+
test_files: []
|
|
100
|
+
|