Class: JekyllImgFlow::TagScanner
- Inherits:
-
Object
- Object
- JekyllImgFlow::TagScanner
- Defined in:
- lib/jekyll-imgflow/tag_scanner.rb
Overview
Scans Jekyll content for imgflow % and picture % tags Uses ManifestManager as single source of truth
Instance Method Summary collapse
-
#determine_version_type(operations) ⇒ Object
Determine if operations represent default or specialized version.
-
#extract_markup_from_line(line, tag_prefix) ⇒ Object
Extract markup from line - reusable method.
-
#extract_operations(markup) ⇒ Object
Extract operations from tag markup - returns raw strings only.
-
#find_imgflow_tags(content) ⇒ Object
Find all imgflow tags in content.
-
#find_picture_tags(content) ⇒ Object
Find all picture tags in content.
-
#initialize(site, config, manifest = nil) ⇒ TagScanner
constructor
A new instance of TagScanner.
-
#parse_tag_markup_simple(markup) ⇒ Object
Simple parsing without regex gymnastics.
-
#scan_all_content ⇒ Object
Scan all content files for image tags Returns summary from ManifestManager instead of building own hash.
-
#scan_content(content) ⇒ Object
Scan raw content string and return array of tag info (for testing/direct use).
-
#scan_content_item(item) ⇒ Object
Scan a single content item Note: With ManifestManager as single source of truth, this just discovers tags Actual tracking happens in ManifestManager during ImgflowTag rendering.
-
#scan_tags_from_content(content, tag_patterns) ⇒ Object
Generic tag scanner - eliminates duplication.
Constructor Details
#initialize(site, config, manifest = nil) ⇒ TagScanner
Returns a new instance of TagScanner.
7 8 9 10 11 |
# File 'lib/jekyll-imgflow/tag_scanner.rb', line 7 def initialize(site, config, manifest = nil) @site = site @config = config @manifest = manifest end |
Instance Method Details
#determine_version_type(operations) ⇒ Object
Determine if operations represent default or specialized version
94 95 96 |
# File 'lib/jekyll-imgflow/tag_scanner.rb', line 94 def determine_version_type(operations) determine_type(operations) end |
#extract_markup_from_line(line, tag_prefix) ⇒ Object
Extract markup from line - reusable method
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/jekyll-imgflow/tag_scanner.rb', line 112 def extract_markup_from_line(line, tag_prefix) start_idx = line.index(tag_prefix) return unless start_idx start_idx += tag_prefix.length end_idx = line.index("%}", start_idx) return unless start_idx && end_idx line[start_idx..(end_idx - 1)].strip end |
#extract_operations(markup) ⇒ Object
Extract operations from tag markup - returns raw strings only
88 89 90 91 |
# File 'lib/jekyll-imgflow/tag_scanner.rb', line 88 def extract_operations(markup) parsed = parse_tag_markup_simple(markup) parsed[:operations] # Just return array of ["width:800", "quality:90"] end |
#find_imgflow_tags(content) ⇒ Object
Find all imgflow tags in content
65 66 67 |
# File 'lib/jekyll-imgflow/tag_scanner.rb', line 65 def (content) scan_content(content) end |
#find_picture_tags(content) ⇒ Object
Find all picture tags in content
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/jekyll-imgflow/tag_scanner.rb', line 70 def (content) = [] # Define tag patterns to scan for tag_patterns = { "picture" => "{% picture" } # Use reusable scanner (content, tag_patterns) do |_tag_name, markup| parsed = parse_tag_markup_simple(markup) << parsed end end |
#parse_tag_markup_simple(markup) ⇒ Object
Simple parsing without regex gymnastics
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/jekyll-imgflow/tag_scanner.rb', line 124 def parse_tag_markup_simple(markup) # Split by whitespace first to get image path parts = markup.split(/\s+/) image_path = parts.shift # Parse operations as key:value pairs separated by commas or spaces operations = [] remaining = parts.join(" ") # Handle comma-separated: key:value,key:value operation_pairs = if remaining.include?(",") remaining.split(",") else # Handle space-separated: key:value key:value remaining.split(/\s+/) end operation_pairs.each do |pair| next if pair.empty? next unless pair.include?(":") key, value = pair.split(":", 2) # Convert numeric values using simple string methods value_stripped = value.strip converted_value = if value_stripped.match?(/^\d+$/) value_stripped.to_i elsif value_stripped.match?(/^\d+\.\d+$/) value_stripped.to_f else value_stripped end # Store with converted value for downstream type correctness operations << "#{key.strip}:#{converted_value}" end { image: image_path, # Use :image key for test compatibility operations: operations # Return as array of strings } end |
#scan_all_content ⇒ Object
Scan all content files for image tags Returns summary from ManifestManager instead of building own hash
15 16 17 18 19 20 21 22 23 |
# File 'lib/jekyll-imgflow/tag_scanner.rb', line 15 def scan_all_content # Scan posts, pages, and documents scannable_content.each do |item| scan_content_item(item) end # Return manifest summary if available, otherwise empty hash @manifest ? @manifest.get_all_versions : {} end |
#scan_content(content) ⇒ Object
Scan raw content string and return array of tag info (for testing/direct use)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jekyll-imgflow/tag_scanner.rb', line 47 def scan_content(content) = [] # Define tag patterns to scan for tag_patterns = { "imgflow" => "{% imgflow" } # Use reusable scanner (content, tag_patterns) do |_tag_name, markup| parsed = parse_tag_markup_simple(markup) << parsed end end |
#scan_content_item(item) ⇒ Object
Scan a single content item Note: With ManifestManager as single source of truth, this just discovers tags Actual tracking happens in ManifestManager during ImgflowTag rendering
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/jekyll-imgflow/tag_scanner.rb', line 28 def scan_content_item(item) content = item.content # Define tag patterns to scan for tag_patterns = { "imgflow" => "{% imgflow", "picture" => "{% picture" } # Use reusable scanner - just for discovery/validation (content, tag_patterns) do |_tag_name, markup| # Tags are discovered but not tracked here # ManifestManager handles all tracking during actual rendering end nil # No longer returns requirements hash end |
#scan_tags_from_content(content, tag_patterns) ⇒ Object
Generic tag scanner - eliminates duplication
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/jekyll-imgflow/tag_scanner.rb', line 99 def (content, tag_patterns) content_lines = content.split("\n") content_lines.each do |line| tag_patterns.each do |tag_name, tag_prefix| next unless line.include?(tag_prefix) markup = extract_markup_from_line(line, tag_prefix) yield tag_name, markup if markup end end end |