Sha256: ac910bf732c26d36d379dc3aa733e3291038eb744a6e223d1ef84da6e68b4f6e

Contents?: true

Size: 1.07 KB

Versions: 11

Compression:

Stored size: 1.07 KB

Contents

%w(pygments.rb github-markdown).each do |lib|
  begin
    require lib.gsub('-', '/')
  rescue LoadError => ex
    raise ex, "In order to use the HtmlSerializer you need the gem `#{lib}` in your Gemfile"
  end
end

module Almodovar
  class ResourcePresenter
    class HtmlSerializer < Serializer

      TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'template.html.erb')

      def to_html
        template = File.read(TEMPLATE_PATH)
        ERB.new(template).result(binding)
      end

      def metadata
        resource.resource_class.metadata
      end

      def beautify(representation, format)
        body = Pygments.highlight(representation, :lexer => format)
        body = body.gsub(/&quot;(http\S+)&quot;/) { url = $1; "&quot;<a href=\"#{url}\">#{url}</a>&quot;" }
        body.html_safe
      end

      def metadata_text(text)
        return if text.blank?

        if indentation = text[/\n\s+/]
          text = text.gsub(indentation, "\n")
        end

        text = text.strip
        text = GitHub::Markdown.render text
        text.html_safe
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
almodovar-server-0.1.0 lib/almodovar-server/resource_presenter/html_serializer.rb
almodovar-0.9.8 lib/almodovar/resource_presenter/html_serializer.rb
almodovar-0.9.7 lib/almodovar/resource_presenter/html_serializer.rb
almodovar-0.9.6 lib/almodovar/resource_presenter/html_serializer.rb
almodovar-0.9.5 lib/almodovar/resource_presenter/html_serializer.rb
almodovar-0.9.4 lib/almodovar/resource_presenter/html_serializer.rb
almodovar-0.9.2 lib/almodovar/resource_presenter/html_serializer.rb
almodovar-0.9.3 lib/almodovar/resource_presenter/html_serializer.rb
almodovar-0.9.1 lib/almodovar/resource_presenter/html_serializer.rb
almodovar-0.9.0 lib/almodovar/resource_presenter/html_serializer.rb
almodovar-0.8.0 lib/almodovar/resource_presenter/html_serializer.rb