Module: Amrita

Module Amrita |
In: | lib/amrita/xml.rb lib/amrita/template.rb lib/amrita/tag.rb lib/amrita/parts.rb lib/amrita/parser.rb lib/amrita/node_expand.rb lib/amrita/node.rb lib/amrita/merge.rb lib/amrita/handlers.rb lib/amrita/format.rb lib/amrita/compiler.rb lib/amrita/ams.rb

Methods

a convert convert convert convert def_tag def_tag2 e format_inline format_pretty noescape pre

Classes and Modules

Module Amrita::CacheManager
Module Amrita::ExpandByMember
Module Amrita::Node
Module Amrita::PartsTemplate
::Class Amrita::PartsTemplate::PartsTempleteExpander
Module Amrita::Sanitizer
Module Amrita::XMLParser
Class Amrita::AmsHandler
Class Amrita::AmsTemplate
Class Amrita::AsIsFormatter
Class Amrita::Attr
Class Amrita::AttrArray
Class Amrita::DummyCacheManager
Class Amrita::Element
Class Amrita::ExpandContext
Class Amrita::Formatter
Class Amrita::HtmlParseError
Class Amrita::HtmlParser
Class Amrita::HtmlTagInfo
Class Amrita::Listener
Class Amrita::MergeTemplate
Class Amrita::ModelMisMatch
Class Amrita::ModuleCache
Class Amrita::NodeArray
Class Amrita::PreFormatter
Class Amrita::PrettyPrintFormatter
Class Amrita::SanitizedString
Class Amrita::SingleLineFormatter
Class Amrita::SourceCache
Class Amrita::Tag
Class Amrita::TagBlock
Class Amrita::TagDD
Class Amrita::TagDT
Class Amrita::TagEmpty
Class Amrita::TagInfo
::Class Amrita::TagInfo::TagInfoItem
Class Amrita::TagInline
Class Amrita::TagItem
Class Amrita::TagList
Class Amrita::TagP
Class Amrita::TagPre
Class Amrita::TagTableSection
Class Amrita::Template
Class Amrita::TemplateFile
Class Amrita::TemplateFileWithCache
Class Amrita::TemplateText

Public Class methods

def_tag(tagname, *attrs_p)

    # File lib/amrita/node.rb, line 749
        def klass::def_tag(tagname, *attrs_p)
          def_tag2(tagname, tagname, *attrs_p)
        end

def_tag2(methodname, tagname, *attrs_p)

    # File lib/amrita/node.rb, line 753
        def klass::def_tag2(methodname, tagname, *attrs_p)
          methodname = methodname.id2name
          tagname = tagname.id2name
          attrs = attrs_p.collect { |a| a.id2name }

          if attrs.size > 0
            param = attrs.collect { |a| "#{a}=nil" }.join(", ")
            param += ",*args,&block"
            method_body = "  e(:#{tagname}, "
            method_body += attrs.collect { |a| "A(:#{a}, #{a})"}.join(", ")
            method_body += ", *args, &block)"
          else
            param = "*args, &block"
            method_body = "  e(:#{tagname}, *args, &block) "
          end
          a = "def #{methodname}(#{param}) \n#{method_body}\nend\n"
          #print a
          eval a
        end

Public Instance methods

convert(s)

    # File lib/amrita/xml.rb, line 15
          def convert(s)
            Uconv::u8toeuc(s)
          end

convert(s)

    # File lib/amrita/xml.rb, line 19
          def convert(s)
            Uconv::u8tosjis(s)
          end

convert(s)

    # File lib/amrita/xml.rb, line 23
          def convert(s)
            s
          end

convert(s)

    # File lib/amrita/xml.rb, line 28
        def convert(s)
          s
        end

e(tagname, *attrs, &block)

e(:hr)
  <hr>
e(:img src="a.png")
  <img src="a.png">
e(:p) { "text" }
  <p>text</p>
e(:span :class=>"fotter") { "bye" }
  <span class="fotter">bye</span>

    # File lib/amrita/node.rb, line 698
      def e(tagname, *attrs, &block)
        Element.new(tagname, *attrs, &block)
      end

a(*x, &block)

generate AttrArray object

    # File lib/amrita/node.rb, line 706
      def a(*x, &block)
        case x.size
        when 1
          x = x[0]
          case x
            when Hash
            when String,Symbol
            x = Attr.new(x)
            when Attr
            else
            raise(TypeError, "Not Attr,String or Symbol: #{x}")
          end
          AttrArray.new(x, &block)
        when 0
          AttrArray.new([], &block)
        else
          a = (0...x.size/2).collect do |i|
            Attr.new(x[i*2], x[i*2+1])
          end
          AttrArray.new(a, &block)
        end
      end

format_inline(data=true, &block) {|| ...}

format a Node object given as `block` in single line format.

If `data` was given, `expand` will be called before formatting

    # File lib/amrita/format.rb, line 686
      def format_inline(data=true, &block)
        node = Node::to_node(yield)
        f = SingleLineFormatter.new
        f.format(node.expand1(data))
      end

format_pretty(data=true, &block) {|| ...}

pretty print a Node object given as `block`

If `data` was given, `expand` will be called before formatting

    # File lib/amrita/format.rb, line 698
      def format_pretty(data=true, &block)
        node = Node::to_node(yield)
        f = PrettyPrintFormatter.new
        f.format(node.expand1(data))
      end

noescape(&block)

Usually the <> character in text will be escaped.

        tmpl = TemplateText.new "<p id=x></p>"
        tmpl.expand(STDOUT, {:x => "<tag>"}) # => <p>&lt;tag&gt;</p>

If the text was wrapped by this method, it will no be escaped.

        tmpl.expand(STDOUT, {:x => noescape {"<tag>"}}) # =>  <p><tag></p>

    # File lib/amrita/format.rb, line 715
      def noescape(&block)
        Escape.new(false, &block)
      end

pre(*attrs, &block)

If the text was wrapped by this method, spaces in it will be keeped.

    # File lib/amrita/format.rb, line 722
      def pre(*attrs, &block)
        Element.new(:pre, *attrs) { CompactSpace.new(false, &block) }
      end