Sha256: 50a0e137c2ac837d108fd33ea45d60db5b8fa06a876b41f6e739b15eaa58c768

Contents?: true

Size: 929 Bytes

Versions: 2

Compression:

Stored size: 929 Bytes

Contents

module EmberCLI
  class HtmlPage
    def initialize(content:, asset_resolver:, head: "", body: "")
      @content = content
      @asset_resolver = asset_resolver
      @head = head
      @body = body
    end

    def render
      if has_head_tag?
        insert_head_content
      end

      if has_body_tag?
        insert_body_content
      end

      html
    end

    private

    def has_head_tag?
      head_tag_index >= 0
    end

    def has_body_tag?
      body_tag_index >= 0
    end

    def insert_head_content
      html.insert(head_tag_index, @head.to_s)
    end

    def insert_body_content
      html.insert(body_tag_index, @body.to_s)
    end

    def html
      @html ||= resolved_html
    end

    def head_tag_index
      html.index("</head") || -1
    end

    def body_tag_index
      html.index("</body") || -1
    end

    def resolved_html
      @asset_resolver.resolve_urls(@content)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ember-cli-rails-0.4.1 lib/ember-cli/html_page.rb
ember-cli-rails-0.4.0 lib/ember-cli/html_page.rb