formidable 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ source :rubygems
4
+
3
5
  # gem "nokogiri"
4
6
 
5
7
  gem "nake"
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ code-cleaner (0.8.2)
5
+ diff-lcs (1.1.2)
6
+ nake (0.0.8)
7
+ term-ansicolor
8
+ rspec (2.6.0)
9
+ rspec-core (~> 2.6.0)
10
+ rspec-expectations (~> 2.6.0)
11
+ rspec-mocks (~> 2.6.0)
12
+ rspec-core (2.6.4)
13
+ rspec-expectations (2.6.0)
14
+ diff-lcs (~> 1.1.2)
15
+ rspec-mocks (2.6.0)
16
+ term-ansicolor (1.0.5)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ code-cleaner
23
+ nake
24
+ rspec
@@ -3,6 +3,6 @@
3
3
 
4
4
  # You might think this is a terrible mess and guess what, you're
5
5
  # right mate! However say thanks to authors of RubyGems, not me.
6
- eval(File.read("form.gemspec")).tap do |specification|
6
+ eval(File.read("formidable.gemspec")).tap do |specification|
7
7
  specification.version = "#{specification.version}.pre"
8
8
  end
@@ -121,7 +121,8 @@ module Formidable
121
121
  renderer Renderers::Form
122
122
 
123
123
  # TODO: prefix should be in the form definition (name or namespace)
124
- def initialize(action, method = "POST", prefix = nil, attributes = Hash.new, raw_data = nil)
124
+ def initialize(action, method = "POST", prefix = nil, attributes = Hash.new, raw_data = Hash.new)
125
+ @raw_data = raw_data
125
126
  self.setup
126
127
  super(:form, nil, attributes.merge!(action: action, method: method), raw_data)
127
128
  set_prefix(prefix) if prefix
@@ -4,9 +4,9 @@
4
4
  module Formidable
5
5
  module Renderers
6
6
  class Renderer
7
- attr_reader :element
8
- def initialize(element)
9
- @element = element
7
+ attr_reader :element, :rendering_block
8
+ def initialize(element, &rendering_block)
9
+ @element, @rendering_block = element, rendering_block
10
10
  end
11
11
 
12
12
  def tag(name, attributes = nil, &block)
@@ -53,7 +53,8 @@ module Formidable
53
53
  end
54
54
  end
55
55
 
56
- class LabeledInputRenderer < SimpleInputRenderer
56
+ # Point of this mixin is that we want to have two classes with the same functionality, but different superclass (so super call will render input or tag, depending on what we want).
57
+ module LabeledElementMixin
57
58
  def render
58
59
  id = element.attributes[:id] || (element.attributes[:id] = "random-#{element.object_id}")
59
60
  buffer = tag(:label, for: id) { element.attributes[:title] || element.attributes[:placeholder] } + "\n"
@@ -61,6 +62,14 @@ module Formidable
61
62
  end
62
63
  end
63
64
 
65
+ class LabeledInputRenderer < SimpleInputRenderer
66
+ include LabeledElementMixin
67
+ end
68
+
69
+ class LabeledTagRenderer < SimpleTagRenderer
70
+ include LabeledElementMixin
71
+ end
72
+
64
73
  class Fieldset < SimpleInputRenderer
65
74
  def render
66
75
  tag(:fieldset) do
@@ -94,6 +103,14 @@ module Formidable
94
103
  set_method(method)
95
104
  end
96
105
 
106
+ if self.rendering_block
107
+ block ||= Proc.new do
108
+ element.elements.map do |element|
109
+ self.instance_exec(element, &rendering_block)
110
+ end.join("\n")
111
+ end
112
+ end
113
+
97
114
  block ||= begin
98
115
  Proc.new do
99
116
  element.elements.map do |element|
@@ -8,7 +8,7 @@ module Formidable
8
8
  klass.extend(ClassMethods)
9
9
  klass.extend Module.new {
10
10
  def inherited(subclass)
11
- subclass.renderer(default_renderer)
11
+ subclass.renderer(default_renderer, &rendering_block)
12
12
  end
13
13
  }
14
14
  end
@@ -17,7 +17,8 @@ module Formidable
17
17
  def renderer
18
18
  @renderer ||= begin
19
19
  renderer = self.class.default_renderer
20
- renderer.new(self) unless renderer.nil?
20
+ rendering_block = self.class.rendering_block
21
+ renderer.new(self, &rendering_block) unless renderer.nil?
21
22
  end
22
23
  end
23
24
 
@@ -32,10 +33,11 @@ module Formidable
32
33
  end
33
34
 
34
35
  module ClassMethods
35
- attr_reader :default_renderer
36
+ attr_reader :default_renderer, :rendering_block
36
37
 
37
- def renderer(default_renderer)
38
+ def renderer(default_renderer, &rendering_block)
38
39
  @default_renderer = default_renderer
40
+ @rendering_block = rendering_block
39
41
  end
40
42
  end
41
43
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Formidable
4
- VERSION = "0.1"
4
+ VERSION ||= "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,11 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formidable
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- version: "0.1"
4
+ prerelease:
5
+ version: 0.1.1
9
6
  platform: ruby
10
7
  authors:
11
8
  - Jakub Stastny aka Botanicus
@@ -13,7 +10,7 @@ authors:
13
10
  autorequire:
14
11
  bindir: bin
15
12
  cert_chain:
16
- date: 2010-11-03 00:00:00 +01:00
13
+ date: 2011-07-18 00:00:00 +01:00
17
14
  default_executable:
18
15
  dependencies: []
19
16
 
@@ -29,6 +26,7 @@ files:
29
26
  - .gitignore
30
27
  - CHANGELOG
31
28
  - Gemfile
29
+ - Gemfile.lock
32
30
  - LICENSE
33
31
  - README.textile
34
32
  - TODO.txt
@@ -70,7 +68,6 @@ files:
70
68
  - spec/spec.opts
71
69
  - spec/spec_helper.rb
72
70
  - tasks.rb
73
- - vendor/cache/validatable-1.6.7.gem
74
71
  has_rdoc: true
75
72
  homepage: http://github.com/botanicus/formidable
76
73
  licenses: []
@@ -85,22 +82,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
82
  requirements:
86
83
  - - ">="
87
84
  - !ruby/object:Gem::Version
88
- segments:
89
- - 1
90
- - 9
91
85
  version: "1.9"
92
86
  required_rubygems_version: !ruby/object:Gem::Requirement
93
87
  none: false
94
88
  requirements:
95
89
  - - ">="
96
90
  - !ruby/object:Gem::Version
97
- segments:
98
- - 0
99
91
  version: "0"
100
92
  requirements: []
101
93
 
102
94
  rubyforge_project: formidable
103
- rubygems_version: 1.3.7
95
+ rubygems_version: 1.6.2
104
96
  signing_key:
105
97
  specification_version: 3
106
98
  summary: ""