Sha256: 64f5a48b562e108055293206b5f21de070931890c15f6c2bbbc5d211a61871e3

Contents?: true

Size: 982 Bytes

Versions: 3

Compression:

Stored size: 982 Bytes

Contents

# frozen_string_literal: true

class Code
  class Object
    class Html < Object
      def self.call(**args)
        code_operator = args.fetch(:operator, nil).to_code
        code_arguments = args.fetch(:arguments, []).to_code

        case code_operator.to_s
        when "link_to"
          sig(args) { [Object.maybe, Object.maybe] }
          code_link_to(*code_arguments.raw)
        when "escape"
          sig(args) { Object.maybe }
          code_escape(*code_arguments.raw)
        else
          super
        end
      end

      def self.code_link_to(text = nil, href = nil)
        code_text = text.to_code
        code_href = href.to_code

        String.new(<<~LINK.strip)
          <a
            href="#{CGI.escapeHTML(code_href.to_s)}"
          >#{CGI.escapeHTML(code_text.to_s)}</a>
        LINK
      end

      def self.code_escape(string = nil)
        code_string = string.to_code

        String.new(CGI.escapeHTML(string.to_s))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
code-ruby-1.2.3 lib/code/object/html.rb
code-ruby-1.2.2 lib/code/object/html.rb
code-ruby-1.2.1 lib/code/object/html.rb