Class: ThemeCheck::Template
- Inherits:
-
Object
- Object
- ThemeCheck::Template
- Defined in:
- lib/theme_check/template.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #excerpt(line) ⇒ Object
- #full_line(line) ⇒ Object
-
#initialize(relative_path, storage) ⇒ Template
constructor
A new instance of Template.
- #json? ⇒ Boolean
- #lines ⇒ Object
- #liquid? ⇒ Boolean
- #name ⇒ Object
- #parse ⇒ Object
- #path ⇒ Object
- #relative_path ⇒ Object
- #root ⇒ Object
- #section? ⇒ Boolean
- #snippet? ⇒ Boolean
- #source ⇒ Object
- #source_excerpt(line) ⇒ Object
- #template? ⇒ Boolean
-
#updated_content ⇒ Object
Not entirely obvious but lines is mutable, corrections are to be applied on @lines.
- #warnings ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(relative_path, storage) ⇒ Template
Returns a new instance of Template.
6 7 8 9 |
# File 'lib/theme_check/template.rb', line 6 def initialize(relative_path, storage) @storage = storage @relative_path = relative_path end |
Class Method Details
.parse(source) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/theme_check/template.rb', line 96 def self.parse(source) Liquid::Template.parse( source, line_numbers: true, error_mode: :warn, ) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
91 92 93 |
# File 'lib/theme_check/template.rb', line 91 def ==(other) other.is_a?(Template) && relative_path == other.relative_path end |
#excerpt(line) ⇒ Object
66 67 68 |
# File 'lib/theme_check/template.rb', line 66 def excerpt(line) lines[line - 1].strip end |
#full_line(line) ⇒ Object
75 76 77 |
# File 'lib/theme_check/template.rb', line 75 def full_line(line) lines[line - 1] end |
#json? ⇒ Boolean
35 36 37 |
# File 'lib/theme_check/template.rb', line 35 def json? false end |
#lines ⇒ Object
55 56 57 58 |
# File 'lib/theme_check/template.rb', line 55 def lines # Retain trailing newline character @lines ||= source.split("\n", -1) end |
#liquid? ⇒ Boolean
39 40 41 |
# File 'lib/theme_check/template.rb', line 39 def liquid? true end |
#name ⇒ Object
31 32 33 |
# File 'lib/theme_check/template.rb', line 31 def name relative_path.sub_ext('').to_s end |
#parse ⇒ Object
79 80 81 |
# File 'lib/theme_check/template.rb', line 79 def parse @ast ||= self.class.parse(source) end |
#path ⇒ Object
11 12 13 |
# File 'lib/theme_check/template.rb', line 11 def path @storage.path(@relative_path) end |
#relative_path ⇒ Object
15 16 17 |
# File 'lib/theme_check/template.rb', line 15 def relative_path @relative_pathname ||= Pathname.new(@relative_path) end |
#root ⇒ Object
87 88 89 |
# File 'lib/theme_check/template.rb', line 87 def root parse.root end |
#section? ⇒ Boolean
47 48 49 |
# File 'lib/theme_check/template.rb', line 47 def section? name.start_with?('sections') end |
#snippet? ⇒ Boolean
51 52 53 |
# File 'lib/theme_check/template.rb', line 51 def snippet? name.start_with?('snippets') end |
#source ⇒ Object
19 20 21 |
# File 'lib/theme_check/template.rb', line 19 def source @source ||= @storage.read(@relative_path) end |
#source_excerpt(line) ⇒ Object
70 71 72 73 |
# File 'lib/theme_check/template.rb', line 70 def source_excerpt(line) original_lines = source.split("\n") original_lines[line - 1].strip end |
#template? ⇒ Boolean
43 44 45 |
# File 'lib/theme_check/template.rb', line 43 def template? name.start_with?('templates') end |
#updated_content ⇒ Object
Not entirely obvious but lines is mutable, corrections are to be applied on @lines.
62 63 64 |
# File 'lib/theme_check/template.rb', line 62 def updated_content lines.join("\n") end |
#warnings ⇒ Object
83 84 85 |
# File 'lib/theme_check/template.rb', line 83 def warnings @ast.warnings end |
#write ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/theme_check/template.rb', line 23 def write content = updated_content if source != content @storage.write(@relative_path, content) @source = content end end |