Class: InstallTheme::Parsers::RailsForm
- Inherits:
-
Object
- Object
- InstallTheme::Parsers::RailsForm
- Defined in:
- lib/install_theme/parsers/rails_form.rb
Instance Attribute Summary collapse
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Class Method Summary collapse
-
.parse(html) ⇒ Object
Parses an HTML page and returns an Array of RailsForm objects Each maps to a <form> tag, and #valid? returns true if a form maps to a Ruby on Rails form.
Instance Method Summary collapse
-
#initialize(form_node) ⇒ RailsForm
constructor
A new instance of RailsForm.
- #render ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(form_node) ⇒ RailsForm
Returns a new instance of RailsForm.
13 14 15 16 17 |
# File 'lib/install_theme/parsers/rails_form.rb', line 13 def initialize(form_node) @form_node = form_node parse_form_info @inputs = @form_node.search('input[@type="text"],textarea').map { |input| parse_input(input) } end |
Instance Attribute Details
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
2 3 4 |
# File 'lib/install_theme/parsers/rails_form.rb', line 2 def inputs @inputs end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/install_theme/parsers/rails_form.rb', line 3 def model @model end |
Class Method Details
.parse(html) ⇒ Object
Parses an HTML page and returns an Array of RailsForm objects Each maps to a <form> tag, and #valid? returns true if a form maps to a Ruby on Rails form.
8 9 10 11 |
# File 'lib/install_theme/parsers/rails_form.rb', line 8 def self.parse(html) doc = Hpricot(html) doc.search('form').map { |form| self.new(form) } end |
Instance Method Details
#render ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/install_theme/parsers/rails_form.rb', line 23 def render if valid? "TODO" else @form_node.to_html end end |
#valid? ⇒ Boolean
19 20 21 |
# File 'lib/install_theme/parsers/rails_form.rb', line 19 def valid? model end |