Class: DYI::Script::SimpleScript

Inherits:
Object
  • Object
show all
Defined in:
lib/dyi/script/simple_script.rb

Overview

Class representing a inline-client-script. The scripting becomes effective only when it is output by SVG format.

Since:

  • 1.0.0

Direct Known Subclasses

EcmaScript::Function, ScriptReference

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, content_type = 'application/ecmascript') ⇒ SimpleScript

Returns a new instance of SimpleScript.

Parameters:

  • body (String)

    body of client scripting

  • content_type (String) (defaults to: 'application/ecmascript')

    content-type of script

Since:

  • 1.0.0



39
40
41
42
# File 'lib/dyi/script/simple_script.rb', line 39

def initialize(body, content_type = 'application/ecmascript')
  @content_type = content_type
  @body = body
end

Instance Attribute Details

#bodyString (readonly)

Returns body of client scripting.

Returns:

  • (String)

    body of client scripting

Since:

  • 1.0.0



35
36
37
# File 'lib/dyi/script/simple_script.rb', line 35

def body
  @body
end

#content_typeString (readonly)

Returns content-type of script.

Returns:

  • (String)

    content-type of script

Since:

  • 1.0.0



33
34
35
# File 'lib/dyi/script/simple_script.rb', line 33

def content_type
  @content_type
end

Instance Method Details

#append_body(script_body) ⇒ Object

Appends script.

Parameters:

  • script_body (String)

    body of client scripting that is appended

Since:

  • 1.0.2



59
60
61
62
63
64
65
# File 'lib/dyi/script/simple_script.rb', line 59

def append_body(script_body)
  if @body.to_s[-1,1] == "\n"
    @body += script_body
  else
    @body = [@body, "\n", script_body].join
  end
end

#contentsObject

Since:

  • 1.0.3



68
69
70
# File 'lib/dyi/script/simple_script.rb', line 68

def contents
  @body
end

#has_uri_reference?Boolean

Returns this script includes reference of external script file.

Returns:

  • (Boolean)

    always returns false

Since:

  • 1.0.0



52
53
54
# File 'lib/dyi/script/simple_script.rb', line 52

def has_uri_reference?
  false
end

#include_external_file?Boolean

Returns this script includes reference of external script file.

Returns:

  • (Boolean)

    always returns false

Since:

  • 1.0.0



46
47
48
# File 'lib/dyi/script/simple_script.rb', line 46

def include_external_file?
  false
end

#write_as(formatter, io = $>) ⇒ Object

Writes the buffer contents of the object.

Parameters:

  • a (Formatter::Base)

    formatter for export

  • io (IO) (defaults to: $>)

    a buffer that is written

Since:

  • 1.0.0



75
76
77
# File 'lib/dyi/script/simple_script.rb', line 75

def write_as(formatter, io=$>)
  formatter.write_script(self, io)
end