Class: CopyTunerClient::Copyray
- Inherits:
-
Object
- Object
- CopyTunerClient::Copyray
- Defined in:
- lib/copy_tuner_client/copyray.rb
Class Method Summary collapse
-
.augment_template(source, key) ⇒ Object
Returns augmented HTML where the source is simply wrapped in an HTML comment with filepath info.
- .next_id ⇒ Object
Class Method Details
.augment_template(source, key) ⇒ Object
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 -->
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/copy_tuner_client/copyray.rb', line 18 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 |
.next_id ⇒ Object
29 30 31 |
# File 'lib/copy_tuner_client/copyray.rb', line 29 def self.next_id @id = (@id ||= 0) + 1 end |