Sha256: 5f3d22c8d92a64ad0a90c9ef91038d6f0fbdb6919acfad3cb1a1b77fe858e06c

Contents?: true

Size: 953 Bytes

Versions: 7

Compression:

Stored size: 953 Bytes

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:
    #   <!-- XRAY START 123 /path/to/file.html -->
    #   <div class=".my-element">
    #     ...
    #   </div>
    #   <!-- XRAY 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 = "<!--XRAY START #{id} #{key} #{CopyTunerClient.configuration.project_url} -->\n<span>#{source}</span>\n<!--XRAY END #{id}-->"
      ActiveSupport::SafeBuffer === source ? ActiveSupport::SafeBuffer.new(augmented) : augmented
    end

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
copy_tuner_client-0.1.1.beta7 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.1.1.beta6 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.1.1.beta5 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.1.1.beta4 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.1.1.beta3 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.1.1.beta2 lib/copy_tuner_client/copyray.rb
copy_tuner_client-0.1.1.beta lib/copy_tuner_client/copyray.rb