Sha256: 55fa157223465b8987c68bb24644e14d3479be1328427dd7ed9f6b43f09bd52e

Contents?: true

Size: 786 Bytes

Versions: 10

Compression:

Stored size: 786 Bytes

Contents

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

    def render
      if has_head_tag?
        insert_head_content
      end

      if has_body_tag?
        insert_body_content
      end

      content
    end

    private

    attr_reader :content

    def has_head_tag?
      head_tag_index >= 0
    end

    def has_body_tag?
      body_tag_index >= 0
    end

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

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

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

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ember-cli-rails-0.6.0 lib/ember_cli/html_page.rb
ember-cli-rails-0.5.8 lib/ember_cli/html_page.rb
ember-cli-rails-0.5.7 lib/ember_cli/html_page.rb
ember-cli-rails-0.5.6 lib/ember_cli/html_page.rb
ember-cli-rails-0.5.5 lib/ember_cli/html_page.rb
ember-cli-rails-0.5.4 lib/ember_cli/html_page.rb
ember-cli-rails-0.5.3 lib/ember_cli/html_page.rb
ember-cli-rails-0.5.2 lib/ember_cli/html_page.rb
ember-cli-rails-0.5.1 lib/ember-cli/html_page.rb
ember-cli-rails-0.5.0 lib/ember-cli/html_page.rb