Sha256: 6ea1585c08ce2aca08e671e1ac842f09b60c57cfb416a38883a001ff281f2f2a

Contents?: true

Size: 1.05 KB

Versions: 22

Compression:

Stored size: 1.05 KB

Contents

module CopyTunerClient
  class Copyray
    # Returns augmented HTML where the source is simply wrapped in an HTML
    # comment with filepath info. Xray.js uses these comments to associate
    # elements with the templates that rendered them.
    #
    # This:
    #   <div class=".my-element">
    #     ...
    #   </div>
    #
    # Becomes:
    #   <!-- COPYRAY START 123 /path/to/file.html -->
    #   <div class=".my-element">
    #     ...
    #   </div>
    #   <!-- COPYRAY END 123 -->
    def self.augment_template(source, key)
      id = next_id
      # skim doesn't allow html comments, so use skim's comment syntax if it's skim
      augmented = if source.present?
                    "<!--COPYRAY START #{id} #{key} #{CopyTunerClient.configuration.project_url} -->\n<span>#{source}</span>\n<!--COPYRAY END #{id}-->"
                  else
                    source
                  end
      ActiveSupport::SafeBuffer === source ? ActiveSupport::SafeBuffer.new(augmented) : augmented
    end

    def self.next_id
      @id = (@id ||= 0) + 1
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
copy_tuner_client-0.4.1 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.4.0 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.3.5 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.3.4 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.3.3 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.3.2 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.3.1 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.3.0 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.2.4 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.2.3 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.2.2 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.2.1 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.2.0 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.1.1.beta19 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.1.1.beta18 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.1.1.beta17 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.1.1.beta16 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.1.1.beta15 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.1.1.beta14 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.1.1.beta13 lib/copy_tuner_client/copyray.rb