Class: ConTeXtSetup::Command
- Defined in:
- lib/tex/context/contextsetup.rb
Overview
Represents a single command with a sequence (the name of the command) and an argument list.
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#file ⇒ Object
Returns the value of attribute file.
-
#generated ⇒ Object
Returns the value of attribute generated.
-
#name ⇒ Object
Returns the value of attribute name.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
-
#variant ⇒ Object
Returns the value of attribute variant.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#cmd_name(with_backslash = true) ⇒ Object
Return the name of the command, translated in the current interface’s language.
-
#cmd_name_html(with_backslash = true) ⇒ Object
Return the name of the command, translated in the current interface’s language.
-
#has_variable? ⇒ Boolean
Return true if the command name has a variable part in it, such as placecombinedlist.
-
#initialize(interface) ⇒ Command
constructor
A new instance of Command.
-
#no_of_arguments(with_optional = true) ⇒ Object
Return the number of arguments the command takes.
- #parse_xml(elt) ⇒ Object
- #to_html ⇒ Object
Methods inherited from SetupXML
Constructor Details
#initialize(interface) ⇒ Command
Returns a new instance of Command.
192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/tex/context/contextsetup.rb', line 192 def initialize(interface) @interface=interface @name=nil @file=nil @variant=1 @environment=false @generated=false @sequence=nil @arguments=[] @inteface=interface @enum=%w( first second third ) super() end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
153 154 155 |
# File 'lib/tex/context/contextsetup.rb', line 153 def arguments @arguments end |
#environment ⇒ Object
Returns the value of attribute environment.
153 154 155 |
# File 'lib/tex/context/contextsetup.rb', line 153 def environment @environment end |
#file ⇒ Object
Returns the value of attribute file.
153 154 155 |
# File 'lib/tex/context/contextsetup.rb', line 153 def file @file end |
#generated ⇒ Object
Returns the value of attribute generated.
153 154 155 |
# File 'lib/tex/context/contextsetup.rb', line 153 def generated @generated end |
#name ⇒ Object
Returns the value of attribute name.
153 154 155 |
# File 'lib/tex/context/contextsetup.rb', line 153 def name @name end |
#sequence ⇒ Object
Returns the value of attribute sequence.
153 154 155 |
# File 'lib/tex/context/contextsetup.rb', line 153 def sequence @sequence end |
#variant ⇒ Object
Returns the value of attribute variant.
153 154 155 |
# File 'lib/tex/context/contextsetup.rb', line 153 def variant @variant end |
Instance Method Details
#==(other) ⇒ Object
257 258 259 260 261 |
# File 'lib/tex/context/contextsetup.rb', line 257 def ==(other) return false unless Command===other @sequence == other.sequence && @environment==other.environment && @arguments == other.arguments && @generated==other.generated end |
#cmd_name(with_backslash = true) ⇒ Object
Return the name of the command, translated in the current interface’s language. Included is the start prefix if the command is an environment and the backslash if with_backslash is set to true (the default).
221 222 223 224 225 226 |
# File 'lib/tex/context/contextsetup.rb', line 221 def cmd_name(with_backslash=true) backslash= with_backslash ? "\\" : "" tmp=environment ? "#{backslash}start" : backslash tmp << @sequence.cmd_name return tmp end |
#cmd_name_html(with_backslash = true) ⇒ Object
Return the name of the command, translated in the current interface’s language. Included is the start prefix if the command is an environment and the backslash if with_backslash is set to true (the default).
231 232 233 234 235 |
# File 'lib/tex/context/contextsetup.rb', line 231 def cmd_name_html(with_backslash=true) tmp=environment ? "\\start" : "\\" tmp << @sequence.cmd_name_html return tmp end |
#has_variable? ⇒ Boolean
Return true if the command name has a variable part in it, such as placecombinedlist.
237 238 239 |
# File 'lib/tex/context/contextsetup.rb', line 237 def has_variable? @sequence.has_variable? end |
#no_of_arguments(with_optional = true) ⇒ Object
Return the number of arguments the command takes. If with_optional is false, return only the number of mandatory arguments.
207 208 209 210 211 212 213 214 215 216 |
# File 'lib/tex/context/contextsetup.rb', line 207 def no_of_arguments(with_optional=true) tmp=@arguments.reject do |arg| unless arg.optional? true unless with_optional else false end end tmp.size end |
#parse_xml(elt) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/tex/context/contextsetup.rb', line 155 def parse_xml(elt) @name = elt.attributes["name"] @file = elt.attributes["file"] @variant = (elt.attributes["variant"] && elt.attributes["variant"].to_i ) || 1 @environment = elt.attributes["type"] == "environment" @generated = elt.attributes["generated"] == "yes" @sequence = Sequence.parse_xml(elt.elements[1],@interface) arguments=elt.elements[2] # if this is a macro without arguments, we can return now and not parse any arguments return unless arguments disp_table = { "keywords" => ConTeXtSetup::Keywords, "triplet" => ConTeXtSetup::Triplet, "assignments" => ConTeXtSetup::Assignments, "content" => ConTeXtSetup::Content, "reference" => ConTeXtSetup::Reference, "word" => ConTeXtSetup::Word, "nothing" => ConTeXtSetup::Nothing, "file" => ConTeXtSetup::File, "csname" => ConTeXtSetup::Csname, "index" => ConTeXtSetup::Index, "position" => ConTeXtSetup::Position, "displaymath" => ConTeXtSetup::Displaymath, "tex" => ConTeXtSetup::TeX, } arguments.each_element do |arg| if disp_table.has_key?(arg.name) @arguments << disp_table[arg.name].send(:parse_xml,arg,@interface) else raise "unknown argument: #{arg.name}" end end end |
#to_html ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/tex/context/contextsetup.rb', line 240 def to_html first_line = [] details = [] @arguments.each_with_index do |arg,i| cls=@enum[ i % @enum.size] opt_or_not_opt = arg.optional? ? span(:class => "optional") { arg.to_html(false) } : arg.to_html(false) first_line << span(:class => cls) { opt_or_not_opt } details << arg.to_html(true, cls) end table(:class => "cmd", :cellspacing => "4", :cellpadding => "2") { tr { td(:colspan => "2", "class" => "cmd") { cmd_name_html(true) + first_line.to_s } } + details.to_s } end |