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.8.7 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.8.6 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.8.5 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.8.4 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.8.3 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.8.2 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.8.1 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.8.0 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.7.5 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.7.4 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.7.3 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.7.2 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.7.1 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.7.0 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.6.3 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.6.2 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.6.1 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.6.0 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.5.5 lib/metanorma/standoc/macros_form.rb
metanorma-standoc-2.5.4 lib/metanorma/standoc/macros_form.rb