Class: AlWidget
- Inherits:
-
Object
- Object
- AlWidget
- Defined in:
- lib/al_form.rb
Overview
ウィジェット スーパークラス
Direct Known Subclasses
Instance Attribute Summary collapse
-
#filter ⇒ String
入力フィルター.
-
#foreign ⇒ Boolean
値が外部で生成されて、フォーム入力ではない事を示すフラグ.
-
#hidden ⇒ Boolean
HTMLタグ input type=“hidden” として生成するかのフラグ.
-
#label ⇒ String
ラベル.
-
#message ⇒ String
readonly
メッセージ.
-
#name ⇒ Symbol
readonly
識別名.
-
#required ⇒ Boolean
必須入力フラグ.
-
#tag_attr ⇒ Hash
Htmlタグ生成時の追加アトリビュート.
-
#tag_type ⇒ String
Htmlタグ生成時のtype文字列.
-
#value ⇒ Object
入力値または初期値.
Instance Method Summary collapse
-
#initialize(name, arg = {}) ⇒ AlWidget
constructor
(AlWidget) constructor.
-
#make_tag(appendix_tag = {}) ⇒ String
(AlWidget) HTMLタグの生成.
-
#make_value(*arg) ⇒ String
(AlWidget) HTML値の生成.
-
#set_attr(arg) ⇒ Object
(AlWidget) アトリビュートの設定.
-
#set_value(v) ⇒ Object
(also: #value=)
(AlWidget) 値のセット.
Constructor Details
#initialize(name, arg = {}) ⇒ AlWidget
(AlWidget) constructor
646 647 648 649 650 651 652 653 654 655 656 657 |
# File 'lib/al_form.rb', line 646 def initialize( name, arg = {} ) @name = name.to_s @label = arg[:label] || @name @value = arg[:value] # (note) 初期値にはfilterをかける必要はないだろう @required = arg[:required] @filter = arg[:filter] @tag_type = arg[:tag_type] if arg[:tag_type] @tag_attr = arg[:tag_attr] || {} @foreign = arg[:foreign] @hidden = arg[:hidden] @message = "" end |
Instance Attribute Details
#filter ⇒ String
Returns 入力フィルター.
614 615 616 |
# File 'lib/al_form.rb', line 614 def filter @filter end |
#foreign ⇒ Boolean
Returns 値が外部で生成されて、フォーム入力ではない事を示すフラグ.
623 624 625 |
# File 'lib/al_form.rb', line 623 def foreign @foreign end |
#hidden ⇒ Boolean
Returns HTMLタグ input type=“hidden” として生成するかのフラグ.
626 627 628 |
# File 'lib/al_form.rb', line 626 def hidden @hidden end |
#label ⇒ String
Returns ラベル.
605 606 607 |
# File 'lib/al_form.rb', line 605 def label @label end |
#message ⇒ String (readonly)
Returns メッセージ.
629 630 631 |
# File 'lib/al_form.rb', line 629 def @message end |
#name ⇒ Symbol (readonly)
Returns 識別名.
602 603 604 |
# File 'lib/al_form.rb', line 602 def name @name end |
#required ⇒ Boolean
Returns 必須入力フラグ.
611 612 613 |
# File 'lib/al_form.rb', line 611 def required @required end |
#tag_attr ⇒ Hash
Returns htmlタグ生成時の追加アトリビュート.
620 621 622 |
# File 'lib/al_form.rb', line 620 def tag_attr @tag_attr end |
#tag_type ⇒ String
Returns htmlタグ生成時のtype文字列.
617 618 619 |
# File 'lib/al_form.rb', line 617 def tag_type @tag_type end |
#value ⇒ Object
Returns 入力値または初期値.
608 609 610 |
# File 'lib/al_form.rb', line 608 def value @value end |
Instance Method Details
#make_tag(appendix_tag = {}) ⇒ String
(AlWidget) HTMLタグの生成
690 691 692 693 694 695 696 697 698 699 |
# File 'lib/al_form.rb', line 690 def make_tag( appendix_tag = {} ) if @hidden return %Q(<input type="hidden" name="#{@name}" id="#{@name}" value="#{Alone::escape_html( @value )}">\n) end r = %Q(<input type="#{@tag_type || "text"}" name="#{@name}" id="#{@name}" value="#{Alone::escape_html( @value )}") make_tag_attr(r, appendix_tag) r << ">" return r end |
#make_value(*arg) ⇒ String
(AlWidget) HTML値の生成
708 709 710 |
# File 'lib/al_form.rb', line 708 def make_value( *arg ) return Alone::escape_html( arg.empty? ? @value : arg[0] ) end |
#set_attr(arg) ⇒ Object
Note:
名称はsetだが、実質はaddである。 一貫していないようだが、テンプレートとの兼ね合いもあり、 この名称の方が自然に記述できる。
(AlWidget) アトリビュートの設定
679 680 681 |
# File 'lib/al_form.rb', line 679 def set_attr( arg ) @tag_attr.merge!( arg ) end |
#set_value(v) ⇒ Object Also known as: value=
(AlWidget) 値のセット
665 666 667 |
# File 'lib/al_form.rb', line 665 def set_value( v ) @value = v end |