Class: Meteor::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/meteor.rb

Overview

要素クラス

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Element

イニシャライザ

Parameters:

  • args (Array)

    引数配列



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/meteor.rb', line 55

def initialize(*args)
  case args.length
    when ONE
      if args[0].kind_of?(String) then
        initialize_s(args[0])
      elsif args[0].kind_of?(Meteor::Element)
        initialize_e(args[0])
      else
        raise ArgumentError
      end
    when TWO
      @name = args[0].name
      @attributes = String.new(args[0].attributes)
      @mixed_content = String.new(args[0].mixed_content)
      #@pattern = String.new(args[0].pattern)
      @pattern = args[0].pattern
      @document = String.new(args[0].document)
      @empty = args[0].empty
      @cx = args[0].cx
      @mono = args[0].mono
      @parser = args[1]
      #@arguments = AttributeMap.new(args[0].arguments)
      #@usable = false
      @origin = args[0]
      args[0].copy = self
    else
      raise ArgumentError
  end
end

Instance Attribute Details

#attributesObject

属性群



138
139
140
# File 'lib/meteor.rb', line 138

def attributes
  @attributes
end

#copyObject

複製ポインタ



152
153
154
# File 'lib/meteor.rb', line 152

def copy
  @copy
end

#cxObject

コメント拡張タグフラグ



145
146
147
# File 'lib/meteor.rb', line 145

def cx
  @cx
end

#document_syncObject

attr_accessor :document #ドキュメントattr_writer :document



143
144
145
# File 'lib/meteor.rb', line 143

def document_sync
  @document_sync
end

#emptyObject

内容存在フラグ



144
145
146
# File 'lib/meteor.rb', line 144

def empty
  @empty
end

#mixed_contentObject

内容



139
140
141
# File 'lib/meteor.rb', line 139

def mixed_content
  @mixed_content
end

#monoObject

子要素存在フラグ



146
147
148
# File 'lib/meteor.rb', line 146

def mono
  @mono
end

#nameObject

要素名



137
138
139
# File 'lib/meteor.rb', line 137

def name
  @name
end

#originObject

原本ポインタ



151
152
153
# File 'lib/meteor.rb', line 151

def origin
  @origin
end

#parserObject

パーサ



147
148
149
# File 'lib/meteor.rb', line 147

def parser
  @parser
end

#patternObject

パターン



140
141
142
# File 'lib/meteor.rb', line 140

def pattern
  @pattern
end

#type_valueObject

タイプ属性



148
149
150
# File 'lib/meteor.rb', line 148

def type_value
  @type_value
end

#usableObject

attr_accessor :arguments #パターン変更用属性マップ



150
151
152
# File 'lib/meteor.rb', line 150

def usable
  @usable
end

Class Method Details

.new!(*args) ⇒ Object

コピーを作成する

Parameters:

  • args (Array)

    引数配列



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/meteor.rb', line 158

def self.new!(*args)
  case args.length
    when ONE
      #self.new_1!(args[0])
      args[0].clone
    when TWO
      @obj = args[1].root_element.element
      if @obj then
        @obj.attributes = String.new(args[0].attributes)
        @obj.mixed_content = String.new(args[0].mixed_content)
        #@obj.pattern = String.new(args[0].pattern)
        @obj.document = String.new(args[0].document)
        #@obj.arguments = AttributeMap.new(args[0].arguments)
        @obj
      else
        @obj = self.new(args[0],args[1])
        args[1].root_element.element = @obj
        @obj
      end
  end
end

Instance Method Details

#[](name) ⇒ String

属性の値or内容を取得する

Parameters:

  • name (String)

    属性の名前

Returns:

  • (String)

    属性の値or内容



278
279
280
281
282
283
284
285
# File 'lib/meteor.rb', line 278

def [](name)
  #if !name.kind_of?(String) || CONTENT_STR != name  then
  if CONTENT_STR != name then
    attribute(name)
  else
    content()
  end
end

#[]=(name, value) ⇒ Object

属性を編集するor内容をセットする

Parameters:

  • name (String)

    属性の名前

  • value (String)

    属性の値or内容



263
264
265
266
267
268
269
270
# File 'lib/meteor.rb', line 263

def []=(name,value)
  #if !name.kind_of?(String) || CONTENT_STR != name then
  if CONTENT_STR != name then
    attribute(name,value)
  else
    @parser.content(self,value)
  end
end

#attribute(*args) ⇒ String

属性を編集する or 属性の値を取得する

Parameters:

  • args (Array)

    引数配列

Returns:

  • (String)

    属性値



225
226
227
# File 'lib/meteor.rb', line 225

def attribute(*args)
  @parser.attribute(self,*args)
end

#attribute_mapMeteor::AttributeMap

属性マップを取得する

Returns:



234
235
236
# File 'lib/meteor.rb', line 234

def attribute_map
  @parser.attribute_map(self)
end

#child(*args) ⇒ Element

子要素を取得する

Parameters:

  • args (Array)

    引数配列

Returns:



206
207
208
# File 'lib/meteor.rb', line 206

def child(*args)
  @parser.element(*args)
end

#cloneObject

複製する



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/meteor.rb', line 183

def clone
  obj = self.parser.element_cache[self.object_id]
  if obj then
    obj.attributes = String.new(self.attributes)
    obj.mixed_content = String.new(self.mixed_content)
    #obj.pattern = String.new(self.pattern)
    obj.document = String.new(self.document)
    #obj.arguments = AttributeMap.new(self.arguments)
    obj.usable = true
    obj
  else
    obj = self.new(self)
    self.parser.element_cache[self.object_id] = obj
    obj
  end
end

#content(*args) ⇒ String

内容をセットする or 内容を取得する

Parameters:

  • args (Array)

    引数配列

Returns:

  • (String)

    内容



244
245
246
# File 'lib/meteor.rb', line 244

def content(*args)
  @parser.content(self,*args)
end

#content=(value) ⇒ Object

内容をセットする

Parameters:

  • value (String)

    内容



253
254
255
# File 'lib/meteor.rb', line 253

def content=(value)
  @parser.content(self,value)
end

#cxtag(*args) ⇒ Meteor::Element

CX(コメント拡張)タグを取得する

Parameters:

  • args (Array)

    引数配列

Returns:



216
217
218
# File 'lib/meteor.rb', line 216

def cxtag(*args)
  @parser.cxtag(*args)
end

#documentObject

ドキュメントを取得する



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/meteor.rb', line 304

def document
  if @document_sync then
    @document_sync = false
    case @parser.doc_type
      when Parser::HTML then
        if @cx then
          #@pattern_cc = '' << SET_CX_1 << elm.name << SPACE << elm.attributes << SET_CX_2 << elm.mixed_content << SET_CX_3 << elm.name << SET_CX_4
          @document = "<!-- @#{@name} #{@attributes} -->#{@mixed_content}<!-- /@#{@name} -->"
        else
          if @empty then
            #@pattern_cc = '' << TAG_OPEN << elm.name << elm.attributes << TAG_CLOSE << elm.mixed_content << TAG_OPEN3 << elm.name << TAG_CLOSE
            @document = "<#{@name}#{@attributes}>#{@mixed_content}</#{@name}>"
          else
            @document = '' << Meteor::Core::Kernel::TAG_OPEN << @name << @attributes << Meteor::Core::Kernel::TAG_CLOSE
          end
        end
      when Parser::XHTML,Parser::XML then
        if @cx then
          #@pattern_cc = '' << SET_CX_1 << elm.name << SPACE << elm.attributes << SET_CX_2 << elm.mixed_content << SET_CX_3 << elm.name << SET_CX_4
          @document = "<!-- @#{@name} #{@attributes} -->#{@mixed_content}<!-- /@#{@name} -->"
        else
          if @empty then
            #@pattern_cc = '' << TAG_OPEN << elm.name << elm.attributes << TAG_CLOSE << elm.mixed_content << TAG_OPEN3 << elm.name << TAG_CLOSE
            @document = "<#{@name}#{@attributes}>#{@mixed_content}</#{@name}>"
          else
            @document = '' << Meteor::Core::Kernel::TAG_OPEN << @name << @attributes << Meteor::Core::Kernel::TAG_CLOSE3
          end
        end
    end
  else
    @document
  end
end

#document=(doc) ⇒ Object



296
297
298
299
# File 'lib/meteor.rb', line 296

def document=(doc)
  @document_sync = false
  @document = doc
end

#execute(*args) ⇒ Object

フッククラスの処理を実行する

Parameters:

  • args (Array)

    引数配列



353
354
355
# File 'lib/meteor.rb', line 353

def execute(*args)
  @parser.execute(self,*args)
end

#flushObject



345
346
347
# File 'lib/meteor.rb', line 345

def flush
  @parser.flush
end

#removeObject

要素を削除する



341
342
343
# File 'lib/meteor.rb', line 341

def remove
  @parser.remove_element(self)
end

#remove_attribute(*args) ⇒ Object

属性を削除する

Parameters:

  • args

    引数配列



292
293
294
# File 'lib/meteor.rb', line 292

def remove_attribute(*args)
  @parser.remove_attribute(self,*args)
end