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
入力値または初期値.
-
#value_format ⇒ String, Nil
Make_valueで使用する変換フォーマット文字列.
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
650 651 652 653 654 655 656 657 658 659 660 661 662 |
# File 'lib/al_form.rb', line 650 def initialize( name, arg = {} ) @name = name.to_s @label = arg[:label] || @name @value = arg[:value] # (note) 初期値にはfilterをかける必要はないだろう @value_format = arg[:value_format] @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 入力フィルター.
618 619 620 |
# File 'lib/al_form.rb', line 618 def filter @filter end |
#foreign ⇒ Boolean
Returns 値が外部で生成されて、フォーム入力ではない事を示すフラグ.
627 628 629 |
# File 'lib/al_form.rb', line 627 def foreign @foreign end |
#hidden ⇒ Boolean
Returns HTMLタグ input type=“hidden” として生成するかのフラグ.
630 631 632 |
# File 'lib/al_form.rb', line 630 def hidden @hidden end |
#label ⇒ String
Returns ラベル.
606 607 608 |
# File 'lib/al_form.rb', line 606 def label @label end |
#message ⇒ String (readonly)
Returns メッセージ.
633 634 635 |
# File 'lib/al_form.rb', line 633 def @message end |
#name ⇒ Symbol (readonly)
Returns 識別名.
603 604 605 |
# File 'lib/al_form.rb', line 603 def name @name end |
#required ⇒ Boolean
Returns 必須入力フラグ.
615 616 617 |
# File 'lib/al_form.rb', line 615 def required @required end |
#tag_attr ⇒ Hash
Returns htmlタグ生成時の追加アトリビュート.
624 625 626 |
# File 'lib/al_form.rb', line 624 def tag_attr @tag_attr end |
#tag_type ⇒ String
Returns htmlタグ生成時のtype文字列.
621 622 623 |
# File 'lib/al_form.rb', line 621 def tag_type @tag_type end |
#value ⇒ Object
Returns 入力値または初期値.
609 610 611 |
# File 'lib/al_form.rb', line 609 def value @value end |
#value_format ⇒ String, Nil
Returns make_valueで使用する変換フォーマット文字列.
612 613 614 |
# File 'lib/al_form.rb', line 612 def value_format @value_format end |
Instance Method Details
#make_tag(appendix_tag = {}) ⇒ String
(AlWidget) HTMLタグの生成
695 696 697 698 699 700 701 702 703 704 |
# File 'lib/al_form.rb', line 695 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値の生成
713 714 715 |
# File 'lib/al_form.rb', line 713 def make_value( *arg ) return Alone::escape_html( arg.empty? ? @value : arg[0] ) end |
#set_attr(arg) ⇒ Object
Note:
名称はsetだが、実質はaddである。一貫していないようだが、テンプレートとの兼ね合いもあり、この名称の方が自然に記述できる。
(AlWidget) アトリビュートの設定
684 685 686 |
# File 'lib/al_form.rb', line 684 def set_attr( arg ) @tag_attr.merge!( arg ) end |
#set_value(v) ⇒ Object Also known as: value=
(AlWidget) 値のセット
670 671 672 |
# File 'lib/al_form.rb', line 670 def set_value( v ) @value = v end |