Class: OmniAuth::Form
- Inherits:
-
Object
- Object
- OmniAuth::Form
- Defined in:
- lib/omniauth/form.rb
Constant Summary collapse
- DEFAULT_CSS =
File.read(File.('../form.css', __FILE__))
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #button(text) ⇒ Object
- #fieldset(legend, options = {}, &block) ⇒ Object
- #footer ⇒ Object
- #header(title, header_info) ⇒ Object
- #html(html) ⇒ Object
-
#initialize(options = {}) ⇒ Form
constructor
A new instance of Form.
- #input_field(type, name) ⇒ Object
- #label_field(text, target) ⇒ Object
- #password_field(label, name) ⇒ Object
- #text_field(label, name) ⇒ Object
- #to_html ⇒ Object
- #to_response ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Form
Returns a new instance of Form.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/omniauth/form.rb', line 7 def initialize( = {}) [:title] ||= 'Authentication Info Required' [:header_info] ||= '' [:method] ||= 'post' self. = @html = +'' # unary + string allows it to be mutable if strings are frozen = false = nil header([:title], [:header_info]) end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/omniauth/form.rb', line 5 def end |
Class Method Details
.build(options = {}, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/omniauth/form.rb', line 19 def self.build( = {}, &block) form = OmniAuth::Form.new() if block.arity > 0 yield form else form.instance_eval(&block) end form end |
Instance Method Details
#button(text) ⇒ Object
51 52 53 54 |
# File 'lib/omniauth/form.rb', line 51 def (text) = true @html << "\n<button type='submit'>#{text}</button>" end |
#fieldset(legend, options = {}, &block) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/omniauth/form.rb', line 60 def fieldset(legend, = {}, &block) @html << "\n<fieldset#{" style='#{options[:style]}'" if options[:style]}#{" id='#{options[:id]}'" if options[:id]}>\n <legend>#{legend}</legend>\n" instance_eval(&block) @html << "\n</fieldset>" self end |
#footer ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/omniauth/form.rb', line 84 def return self if @html << "\n<button type='submit'>Connect</button>" unless @html << " </form>\n </body>\n </html>\n HTML\n @footer = true\n self\nend\n" |
#header(title, header_info) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/omniauth/form.rb', line 67 def header(title, header_info) @html << " <!DOCTYPE html>\n <html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n <title>\#{title}</title>\n \#{css}\n \#{header_info}\n </head>\n <body>\n <h1>\#{title}</h1>\n <form method='\#{options[:method]}' \#{\"action='\#{options[:url]}' \" if options[:url]}noValidate='noValidate'>\n HTML\n self\nend\n" |
#html(html) ⇒ Object
56 57 58 |
# File 'lib/omniauth/form.rb', line 56 def html(html) @html << html end |
#input_field(type, name) ⇒ Object
34 35 36 37 |
# File 'lib/omniauth/form.rb', line 34 def input_field(type, name) @html << "\n<input type='#{type}' id='#{name}' name='#{name}'/>" self end |
#label_field(text, target) ⇒ Object
29 30 31 32 |
# File 'lib/omniauth/form.rb', line 29 def label_field(text, target) @html << "\n<label for='#{target}'>#{text}:</label>" self end |
#password_field(label, name) ⇒ Object
45 46 47 48 49 |
# File 'lib/omniauth/form.rb', line 45 def password_field(label, name) label_field(label, name) input_field('password', name) self end |
#text_field(label, name) ⇒ Object
39 40 41 42 43 |
# File 'lib/omniauth/form.rb', line 39 def text_field(label, name) label_field(label, name) input_field('text', name) self end |
#to_html ⇒ Object
97 98 99 100 |
# File 'lib/omniauth/form.rb', line 97 def to_html @html end |
#to_response ⇒ Object
102 103 104 105 |
# File 'lib/omniauth/form.rb', line 102 def to_response Rack::Response.new(@html, 200, 'content-type' => 'text/html').finish end |