Sha256: 996266ef76ebb7c0bc38a0ab6e9653c2eb52d1ce00c2c3c0af174f6f71374a68

Contents?: true

Size: 1.87 KB

Versions: 83

Compression:

Stored size: 1.87 KB

Contents

module Metanorma
  module Standoc
    class FormInputMacro < Asciidoctor::Extensions::InlineMacroProcessor
      use_dsl
      named :input

      def process(_parent, target, attr)
        m = %w(id name value disabled readonly checked maxlength minlength)
          .map { |a| attr[a] ? " #{a}='#{attr[a]}'" : nil }.compact
        %{<input type='#{target}' #{m.join}/>}
      end
    end

    class FormLabelMacro < Asciidoctor::Extensions::InlineMacroProcessor
      use_dsl
      named :label
      parse_content_as :text

      def process(parent, target, attr)
        out = Asciidoctor::Inline.new(parent, :quoted, attr["text"]).convert
        %{<label for="#{target}">#{out}</label>}
      end
    end

    class FormTextareaMacro < Asciidoctor::Extensions::InlineMacroProcessor
      use_dsl
      named :textarea
      using_format :short

      def process(_parent, _target, attr)
        m = %w(id name rows cols value)
          .map { |a| attr[a] ? " #{a}='#{attr[a]}'" : nil }.compact
        %{<textarea #{m.join}/>}
      end
    end

    class FormSelectMacro < Asciidoctor::Extensions::InlineMacroProcessor
      use_dsl
      named :select
      using_format :short

      def process(parent, _target, attr)
        m = %w(id name size disabled multiple value)
          .map { |a| attr[a] ? " #{a}='#{attr[a]}'" : nil }.compact
        out = Asciidoctor::Inline.new(parent, :quoted, attr["text"]).convert
        %{<select #{m.join}>#{out}</select>}
      end
    end

    class FormOptionMacro < Asciidoctor::Extensions::InlineMacroProcessor
      use_dsl
      named :option
      using_format :short

      def process(parent, _target, attr)
        m = %w(disabled value)
          .map { |a| attr[a] ? " #{a}='#{attr[a]}'" : nil }.compact
        out = Asciidoctor::Inline.new(parent, :quoted, attr["text"]).convert
        %{<option #{m.join}>#{out}</option>}
      end
    end
  end
end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
metanorma-standoc-2.5.3 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.5.2 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.5.1 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.5.0 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.4.9 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.4.8 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.4.7 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.4.6 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.4.5 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.4.4 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.4.3 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.4.2 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.4.1 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.4.0 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.3.9 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.3.8 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.3.7 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.3.6 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.3.5 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.3.4 lib/metanorma/standoc/macros_form.rb