Class: InstallTheme::Parsers::RailsForm

Inherits:
Object
  • Object
show all
Defined in:
lib/install_theme/parsers/rails_form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#inputsObject (readonly)

Returns the value of attribute inputs.



2
3
4
# File 'lib/install_theme/parsers/rails_form.rb', line 2

def inputs
  @inputs
end

#modelObject (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

#renderObject



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

Returns:

  • (Boolean)


19
20
21
# File 'lib/install_theme/parsers/rails_form.rb', line 19

def valid?
  model
end