blueprint-html2slim 1.0.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 460bb27c7423062c1fe30a58b2f432f370361e1134a933ca550644e5f8d05b99
4
- data.tar.gz: d0cace18262a72410fe46ac69ae055523aec83f51d2da1c6fb8cd7cda137544c
3
+ metadata.gz: d27f4f166468ae3be90116e4ff94d8c9901eb72a033ef69b14822d6ed8ce8273
4
+ data.tar.gz: c7916bc01602176018608dc723e49816670d6e6688d890aedde2ec09b4901a4a
5
5
  SHA512:
6
- metadata.gz: '08bd9ceb42074244e5323c01120dff8bf91c1daaedee6574b9e09a994b286996ac3bad0e7f4a0e104066890e87943348c4dcfe11ea954fd4ee492149366059c5'
7
- data.tar.gz: 59b01b4f8f0d86ca4cab804e246149d37dbc57ccb2345687b181b79dd0e878ee7f3e4c72a4c41921b8e2f73b343f005d817247b9cd15920dd0401e732dc4fad9
6
+ metadata.gz: d019b9a611db510f8bd3ed39187c651c40dbd1dab414e7012cbb97d8e4cf06222034d45a1d06db44bf7709a3b822a12021af205fccf5b3482c325b9ca3377f89
7
+ data.tar.gz: 21da628071a957513c4faa67aedb8fe63ee76274efc3c9f08f6c0aeeae353b89017e7785b7fb144a8378718aaf297b9cebf1ba61ad9a623e79de411aad045dc1
data/CHANGELOG.md CHANGED
@@ -2,14 +2,96 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [1.3.0] - 2025-01-16
6
+
7
+ ### Added
8
+ - **SlimExtractor enhancements**:
9
+ - Extract outline up to specified depth (`--outline N`) for high-level structure analysis
10
+ - Extract fragments by CSS selector (`--selector`) supporting #id, .class, element, and combinations
11
+ - **Comprehensive documentation**:
12
+ - Complete README with detailed examples for all commands
13
+ - All command options now have descriptive help text
14
+ - Added workflow examples and use cases
15
+ - Table of contents for easy navigation
16
+
17
+ ### Changed
18
+ - Improved command-line help system with detailed option descriptions
19
+ - Fixed extraction logic bug where keep/remove functionality wasn't working correctly
20
+ - Enhanced help output with categorized examples
21
+
22
+ ### Fixed
23
+ - SlimExtractor now correctly handles keep/remove section logic
24
+ - Thor deprecation warnings resolved with `exit_on_failure?` method
25
+ - RuboCop style violations corrected
26
+
27
+ ## [1.2.0] - 2025-01-16
28
+
29
+ ### Added
30
+ - New `slimtool` command-line utility for comprehensive Slim template manipulation
31
+ - **SlimFixer**: Automatically fixes common Slim syntax issues
32
+ - Fixes text starting with "/" that would be interpreted as comments (converts to pipe notation)
33
+ - Fixes multiline text blocks using proper pipe notation
34
+ - Supports backup and dry-run modes
35
+ - **SlimExtractor**: Extract or remove specific sections from Slim templates
36
+ - Remove unwanted sections (doctype, head, nav, footer, script, etc.)
37
+ - Keep only specified sections (main, article, or any element/class/id)
38
+ - Remove outer wrapper elements
39
+ - Extract outline up to specified depth (high-level structure only)
40
+ - Extract fragments by CSS selector (#id, .class, element, element.class#id)
41
+ - Custom output file support
42
+ - **SlimValidator**: Validate Slim syntax and check for potential issues
43
+ - Detects syntax errors (invalid indentation, unclosed brackets, empty Ruby markers)
44
+ - Strict mode: checks for tabs, inline styles, long lines
45
+ - Rails mode: checks for hardcoded URLs, static assets, missing CSRF tokens
46
+ - Comprehensive error and warning reporting
47
+ - **SlimRailsifier**: Convert static templates to Rails conventions
48
+ - Configurable link mappings via JSON/YAML files (no automatic guessing)
49
+ - Convert CDN assets to Rails asset pipeline helpers
50
+ - Add CSRF protection meta tags to forms
51
+ - Supports dry-run and backup modes
52
+ - **LinkExtractor**: Extract and analyze hardcoded links from templates
53
+ - Find all static HTML links, forms, assets, and images
54
+ - Categorize link types and suggest Rails helper conversions
55
+ - Multiple output formats (JSON, YAML, text)
56
+ - Batch processing of multiple files
57
+ - Comprehensive test suite for all new SlimTool features
58
+
59
+ ### Changed
60
+ - Updated gem to include both `html2slim` and `slimtool` executables
61
+ - Rails link conversions now require explicit mappings (removed automatic fallback guessing)
62
+ - Improved command-line help with detailed examples and option descriptions
63
+
64
+ ## [1.1.0] - 2025-01-16
65
+
66
+ ### Added
67
+ - Unicode/UTF-8 character support (CJK, emoji, European accents, Cyrillic, Arabic, Hebrew)
68
+ - Multiline ERB code block handling using `ruby:` blocks for better Slim syntax
69
+ - Support for inline arrays with chained methods in ERB blocks
70
+
71
+ ### Fixed
72
+ - Text starting with "/" now uses pipe notation to avoid being interpreted as Slim comments
73
+ - Multiline Ruby code (hashes, arrays, method calls) now generates valid Slim syntax
74
+ - UTF-8 encoding issues in CLI tool when reading and writing files
75
+
76
+ ### Changed
77
+ - Improved handling of complex ERB structures with proper indentation
78
+ - Better detection and formatting of multiline ERB blocks
79
+ - Updated RuboCop configuration to disable unnecessary cops
80
+
5
81
  ## [1.0.0] - 2024-01-01
6
82
 
7
83
  ### Added
8
84
  - Initial release of blueprint-html2slim
9
- - HTML to Slim conversion
10
- - ERB template support
11
- - Smart file naming conventions
85
+ - HTML to Slim conversion with full HTML5 support
86
+ - ERB template support with proper Ruby code handling
87
+ - Smart file naming conventions (.html → .html.slim, .erb → .slim)
12
88
  - Backup option for source files
13
89
  - Recursive directory processing
14
- - Dry-run mode
15
- - Custom output path support
90
+ - Dry-run mode for previewing conversions
91
+ - Custom output path support
92
+ - Force overwrite option
93
+ - Delete source files after conversion
94
+ - Target directory support with structure preservation
95
+ - Custom indentation size support
96
+ - Comprehensive test suite with RSpec
97
+ - RuboCop integration for code quality
data/README.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # Blueprint HTML2Slim
2
2
 
3
- A Ruby gem providing a command-line tool to convert HTML and ERB files to Slim format.
3
+ A comprehensive Ruby gem providing tools to convert HTML/ERB files to Slim format and manipulate Slim templates.
4
+
5
+ **Online Converter**: Try the web-based version at [https://railsblueprint.com/html2slim](https://railsblueprint.com/html2slim)
6
+
7
+ ## Table of Contents
8
+ - [Requirements](#requirements)
9
+ - [Installation](#installation)
10
+ - [Tools Included](#tools-included)
11
+ - [HTML2Slim Converter](#html2slim-converter)
12
+ - [SlimTool - Template Manipulation](#slimtool---template-manipulation)
13
+ - [Features Overview](#features-overview)
14
+ - [Contributing](#contributing)
15
+ - [License](#license)
4
16
 
5
17
  ## Requirements
6
18
 
@@ -26,7 +38,13 @@ Or install it yourself as:
26
38
  gem install blueprint-html2slim
27
39
  ```
28
40
 
29
- ## Usage
41
+ ## Tools Included
42
+
43
+ This gem provides two command-line tools:
44
+ 1. **html2slim** - Convert HTML/ERB files to Slim format
45
+ 2. **slimtool** - Manipulate and fix existing Slim files
46
+
47
+ ## HTML2Slim Converter
30
48
 
31
49
  ### Programmatic Usage (Ruby)
32
50
 
@@ -60,77 +78,386 @@ converter = Blueprint::Html2Slim::Converter.new(indent_size: 4)
60
78
 
61
79
  ### Command Line Usage
62
80
 
63
- Convert a single file:
81
+ #### Basic Conversion
82
+
64
83
  ```bash
84
+ # Convert a single file
65
85
  html2slim index.html
66
86
  # Creates: index.html.slim
67
- ```
68
87
 
69
- Convert with custom output:
70
- ```bash
88
+ # Convert with custom output
71
89
  html2slim -o custom.slim index.html
72
- ```
73
90
 
74
- Convert multiple files:
75
- ```bash
91
+ # Convert multiple files
76
92
  html2slim file1.html file2.erb file3.html.erb
77
93
  ```
78
94
 
79
- Convert and backup original files:
95
+ #### File Management Options
96
+
80
97
  ```bash
98
+ # Create backup of original files
81
99
  html2slim -b index.html
82
100
  # Creates: index.html.slim
83
101
  # Renames: index.html -> index.html.bak
102
+
103
+ # Delete source files after conversion
104
+ html2slim -d old_templates/*.erb
105
+ # Converts and deletes the original .erb files
106
+
107
+ # Force overwrite without prompting
108
+ html2slim -f existing.html
84
109
  ```
85
110
 
86
- Convert files in a directory recursively:
111
+ #### Directory Processing
112
+
87
113
  ```bash
114
+ # Convert files in a directory recursively
88
115
  html2slim -r ./views
89
- ```
90
116
 
91
- Convert to target directory (preserves structure):
92
- ```bash
117
+ # Convert to target directory (preserves structure)
93
118
  html2slim -t dist/ -r src/
94
119
  # Converts src/views/index.html to dist/views/index.html.slim
95
120
  ```
96
121
 
97
- Delete source files after conversion:
98
- ```bash
99
- html2slim -d old_templates/*.erb
100
- # Converts and deletes the original .erb files
101
- ```
122
+ #### Preview and Testing
102
123
 
103
- Dry run (preview what would be converted):
104
124
  ```bash
125
+ # Dry run (preview what would be converted)
105
126
  html2slim -n file.html
127
+
128
+ # Custom indentation (default: 2 spaces)
129
+ html2slim -i 4 template.html
106
130
  ```
107
131
 
108
- ## Naming Convention
132
+ ### Naming Conventions
109
133
 
110
134
  - `file.html` → `file.html.slim`
111
135
  - `file.html.erb` → `file.html.slim`
112
136
  - `file.erb` → `file.slim`
113
137
 
114
- ## Options
138
+ ### All HTML2Slim Options
115
139
 
116
- - `-o, --output FILE` - Output file path (only for single file conversion)
140
+ - `-o, --output FILE` - Output file path (single file only)
117
141
  - `-r, --recursive` - Process directories recursively
118
- - `-n, --dry-run` - Show what would be converted without actually converting
142
+ - `-n, --dry-run` - Preview conversions without modifying files
119
143
  - `-d, --delete` - Delete source files after successful conversion
120
- - `-t, --target-dir DIR` - Target directory for converted files (preserves directory structure)
144
+ - `-t, --target-dir DIR` - Target directory for converted files
121
145
  - `-f, --force` - Overwrite existing files without prompting
122
- - `-b, --backup` - Backup source files with .bak extension
146
+ - `-b, --backup` - Create .bak backup of source files
123
147
  - `-i, --indent SIZE` - Indentation size in spaces (default: 2)
124
148
  - `-h, --help` - Show help message
125
149
  - `-v, --version` - Show version
126
150
 
127
- ## Features
151
+ ## SlimTool - Template Manipulation
152
+
153
+ The `slimtool` command provides advanced manipulation capabilities for Slim files.
154
+
155
+ ### 1. Fix Common Syntax Issues
156
+
157
+ Automatically fix common Slim syntax problems:
158
+
159
+ ```bash
160
+ # Fix text starting with forward slash (e.g., span /month)
161
+ slimtool fix pricing.slim
162
+
163
+ # Fix with backup
164
+ slimtool fix template.slim --backup
165
+
166
+ # Preview fixes without modifying
167
+ slimtool fix template.slim --dry-run
168
+
169
+ # Fix multiple files
170
+ slimtool fix views/*.slim
171
+ ```
172
+
173
+ **Options:**
174
+ - `--fix-slashes` - Fix forward slashes in text (default: true)
175
+ - `--fix-multiline` - Fix multiline text blocks (default: true)
176
+ - `-b, --backup` - Create .bak backup before fixing
177
+ - `-n, --dry-run` - Preview changes without modifying files
178
+
179
+ **What it fixes:**
180
+ - Text starting with `/` that would be interpreted as comments
181
+ - Multiline text that should use pipe notation
182
+ - Common indentation issues
183
+
184
+ ### 2. Extract Content Sections
185
+
186
+ Extract or remove specific sections from Slim templates:
187
+
188
+ ```bash
189
+ # Remove unwanted sections
190
+ slimtool extract page.slim --remove head,nav,footer
191
+
192
+ # Keep only specific sections
193
+ slimtool extract page.slim --keep main,article
194
+
195
+ # Remove outer wrapper div
196
+ slimtool extract page.slim --remove-wrapper
197
+
198
+ # Extract outline (high-level structure only)
199
+ slimtool extract page.slim --outline 2
200
+ # Extracts only elements at depth 0 and 1
201
+
202
+ # Extract by CSS selector
203
+ slimtool extract page.slim --selector "#content"
204
+ slimtool extract page.slim --selector ".main-section"
205
+ slimtool extract page.slim --selector "article.featured"
206
+
207
+ # Custom output file
208
+ slimtool extract page.slim --output clean.slim
209
+ ```
210
+
211
+ **Options:**
212
+ - `--keep SECTIONS` - Keep only specified sections
213
+ - `--remove SECTIONS` - Remove specified sections
214
+ - `-o, --output FILE` - Output file path
215
+ - `--remove-wrapper` - Remove single outer wrapper
216
+ - `--outline N` - Extract outline up to depth N
217
+ - `--selector CSS` - Extract fragment by CSS selector
218
+
219
+ **Supported CSS Selectors:**
220
+ - Element: `article`, `main`, `div`
221
+ - ID: `#content`, `#sidebar`
222
+ - Class: `.container`, `.main-section`
223
+ - Combined: `article.featured`, `div#main.container`
224
+
225
+ ### 3. Validate Slim Syntax
226
+
227
+ Check for syntax errors and potential issues:
228
+
229
+ ```bash
230
+ # Basic validation
231
+ slimtool validate template.slim
232
+
233
+ # Validate multiple files
234
+ slimtool validate views/**/*.slim
235
+
236
+ # Strict validation (style checks)
237
+ slimtool validate template.slim --strict
238
+
239
+ # Check Rails conventions
240
+ slimtool validate app.slim --check-rails
241
+
242
+ # Combined strict + Rails checks
243
+ slimtool validate *.slim --strict --check-rails
244
+ ```
245
+
246
+ **Options:**
247
+ - `--strict` - Enable strict mode checks
248
+ - `--check-rails` - Check Rails best practices
249
+
250
+ **What it checks:**
251
+
252
+ **Basic validation:**
253
+ - Invalid indentation
254
+ - Unclosed brackets
255
+ - Empty Ruby code markers (`=` or `-` with no code)
256
+ - Text starting with `/` (would be interpreted as comment)
257
+
258
+ **Strict mode (`--strict`):**
259
+ - Tabs in indentation (enforces spaces only)
260
+ - Inline styles (suggests using CSS classes)
261
+ - Lines exceeding 120 characters
262
+ - Deprecated Slim syntax
263
+
264
+ **Rails checks (`--check-rails`):**
265
+ - Static asset links (suggests asset pipeline helpers)
266
+ - Hardcoded URLs (suggests Rails path helpers)
267
+ - Forms without Rails helpers
268
+ - Missing CSRF tokens in forms
269
+ - CDN assets that could use asset pipeline
270
+
271
+ ### 4. Convert to Rails Conventions
272
+
273
+ Transform static Slim templates to use Rails helpers:
274
+
275
+ ```bash
276
+ # Create a mappings file for URL conversions
277
+ cat > mappings.json << 'EOF'
278
+ {
279
+ "/": "root_path",
280
+ "/about": "about_path",
281
+ "/users": "users_path",
282
+ "/login": "new_session_path",
283
+ "/products": "products_path"
284
+ }
285
+ EOF
286
+
287
+ # Convert using mappings
288
+ slimtool railsify template.slim --mappings mappings.json
289
+
290
+ # Add CSRF protection to forms
291
+ slimtool railsify form.slim --add-csrf --mappings mappings.json
292
+
293
+ # Convert CDN assets to Rails asset pipeline
294
+ slimtool railsify layout.slim --use-assets
295
+
296
+ # Preview changes
297
+ slimtool railsify template.slim --mappings mappings.json --dry-run
298
+
299
+ # Process multiple files with backup
300
+ slimtool railsify views/*.slim --mappings mappings.json --backup
301
+ ```
302
+
303
+ **Options:**
304
+ - `--mappings FILE` - JSON/YAML file with URL-to-helper mappings
305
+ - `--add-helpers` - Convert links to Rails helpers (default: true)
306
+ - `--use-assets` - Convert CDN assets to asset pipeline (default: true)
307
+ - `--add-csrf` - Add CSRF meta tags to head section
308
+ - `-b, --backup` - Create .bak backup before converting
309
+ - `-n, --dry-run` - Preview changes without modifying
310
+
311
+ **What it converts:**
312
+ - Static links to Rails path helpers (using your mappings)
313
+ - CDN stylesheets to `stylesheet_link_tag`
314
+ - CDN scripts to `javascript_include_tag`
315
+ - Static forms to include CSRF tokens
316
+ - Image paths to use `image_tag` helper
317
+
318
+ **Note:** Link conversions require explicit mappings - no automatic guessing.
319
+
320
+ ### 5. Extract Hardcoded Links
321
+
322
+ Find and report all hardcoded links in templates:
323
+
324
+ ```bash
325
+ # Display found links
326
+ slimtool extract-links template.slim
327
+
328
+ # Process multiple files
329
+ slimtool extract-links views/**/*.slim
330
+
331
+ # Save results to JSON
332
+ slimtool extract-links *.slim -o links.json
333
+
334
+ # Save in different formats
335
+ slimtool extract-links *.slim -o links.yaml --format yaml
336
+ slimtool extract-links *.slim -o links.txt --format text
337
+
338
+ # Find links in entire project
339
+ slimtool extract-links app/views/**/*.slim -o project_links.json
340
+ ```
341
+
342
+ **Options:**
343
+ - `-o, --output FILE` - Save results to file
344
+ - `--format FORMAT` - Output format: json, yaml, or text (default: json)
345
+
346
+ **What it finds:**
347
+ - HTML anchor links (`a[href]`)
348
+ - Form action URLs
349
+ - Asset links (stylesheets, scripts)
350
+ - Image sources
351
+ - Any hardcoded paths that could use Rails helpers
352
+
353
+ **Output includes:**
354
+ - File location
355
+ - Line number
356
+ - Link type (anchor, form, asset, image)
357
+ - Original URL
358
+ - Suggested Rails helper (when applicable)
359
+
360
+ ## Features Overview
361
+
362
+ ### HTML2Slim Converter Features
363
+ - ✅ Full HTML5 support
364
+ - ✅ ERB template conversion
365
+ - ✅ Preserves all attributes and structure
366
+ - ✅ Smart ID/class shortcuts (`div#id.class`)
367
+ - ✅ Handles void elements correctly
368
+ - ✅ Preserves comments
369
+ - ✅ Unicode/UTF-8 support
370
+ - ✅ Multiline ERB code blocks
371
+ - ✅ Custom indentation
372
+ - ✅ Batch processing
373
+ - ✅ Directory recursion
374
+
375
+ ### SlimTool Features
376
+ - ✅ **Syntax Fixing**
377
+ - Text starting with `/` (pipe notation)
378
+ - Multiline text blocks
379
+ - Common indentation issues
380
+
381
+ - ✅ **Content Extraction**
382
+ - Remove unwanted sections
383
+ - Keep specific sections
384
+ - Extract by CSS selector
385
+ - Extract outline by depth
386
+ - Remove wrapper elements
387
+
388
+ - ✅ **Validation**
389
+ - Syntax error detection
390
+ - Style checking (strict mode)
391
+ - Rails convention checking
392
+ - Comprehensive error reporting
393
+
394
+ - ✅ **Rails Integration**
395
+ - Convert links to helpers
396
+ - Asset pipeline integration
397
+ - CSRF token support
398
+ - Form helper suggestions
399
+
400
+ - ✅ **Link Analysis**
401
+ - Find all hardcoded URLs
402
+ - Categorize link types
403
+ - Suggest Rails helpers
404
+ - Multiple output formats
405
+
406
+ ## Examples
407
+
408
+ ### Complete Workflow Example
409
+
410
+ ```bash
411
+ # 1. Convert HTML/ERB files to Slim
412
+ html2slim -r ./app/views_old -t ./app/views
413
+
414
+ # 2. Fix any syntax issues
415
+ slimtool fix app/views/**/*.slim --backup
416
+
417
+ # 3. Validate the converted files
418
+ slimtool validate app/views/**/*.slim --strict --check-rails
419
+
420
+ # 4. Extract hardcoded links for analysis
421
+ slimtool extract-links app/views/**/*.slim -o links.json
422
+
423
+ # 5. Create mappings based on found links
424
+ cat > url_mappings.json << 'EOF'
425
+ {
426
+ "/": "root_path",
427
+ "/dashboard": "dashboard_path",
428
+ "/users": "users_path",
429
+ "/login": "new_session_path"
430
+ }
431
+ EOF
432
+
433
+ # 6. Convert to Rails conventions
434
+ slimtool railsify app/views/**/*.slim --mappings url_mappings.json --add-csrf
435
+
436
+ # 7. Final validation
437
+ slimtool validate app/views/**/*.slim --check-rails
438
+ ```
439
+
440
+ ### Cleaning Up Templates
441
+
442
+ ```bash
443
+ # Remove all navigation and footer from templates
444
+ slimtool extract views/*.slim --remove head,nav,footer,script
445
+
446
+ # Extract only the main content area
447
+ slimtool extract page.slim --selector "#main-content" -o clean.slim
448
+
449
+ # Get high-level structure for documentation
450
+ slimtool extract complex_page.slim --outline 2 -o structure.slim
451
+ ```
452
+
453
+ ## Contributing
454
+
455
+ 1. Fork it
456
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
457
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
458
+ 4. Push to the branch (`git push origin my-new-feature`)
459
+ 5. Create new Pull Request
460
+
461
+ ## License
128
462
 
129
- - Converts HTML tags to Slim syntax
130
- - Handles HTML attributes, IDs, and classes
131
- - Preserves ERB tags (<%= %> and <% %>)
132
- - Supports nested elements
133
- - Handles void elements correctly
134
- - Preserves comments
135
- - Smart output file naming
136
- - Optional source file backup
463
+ This gem is available as open source under the terms of the [MIT License](LICENSE).
data/bin/html2slim CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require 'thor'
4
3
  require 'pathname'
5
4
  require_relative '../lib/blueprint/html2slim'
@@ -42,7 +41,7 @@ class Html2SlimCLI < Thor
42
41
  puts ' html2slim -d old_views/*.erb # Convert and delete sources'
43
42
  exit 0
44
43
  elsif given_args.first == 'version' || given_args.include?('-v') || given_args.include?('--version')
45
- puts 'html2slim 1.0.0'
44
+ puts 'html2slim 1.1.0'
46
45
  exit 0
47
46
  else
48
47
  args = given_args.dup
@@ -71,15 +70,13 @@ class Html2SlimCLI < Thor
71
70
  puts 'Error: -o/--output can only be used with a single input file'
72
71
  exit 1
73
72
  end
74
-
73
+
75
74
  if options[:output] && options[:target_dir]
76
75
  puts 'Error: Cannot use both -o/--output and -t/--target-dir together'
77
76
  exit 1
78
77
  end
79
-
80
- if options[:backup] && options[:delete]
81
- puts 'Warning: -b/--backup takes precedence over -d/--delete'
82
- end
78
+
79
+ puts 'Warning: -b/--backup takes precedence over -d/--delete' if options[:backup] && options[:delete]
83
80
 
84
81
  converter = Blueprint::Html2Slim::Converter.new(indent_size: options[:indent])
85
82
  processed_count = 0
@@ -136,7 +133,7 @@ class Html2SlimCLI < Thor
136
133
  else
137
134
  input_path.basename
138
135
  end
139
-
136
+
140
137
  # Apply smart naming convention to the filename
141
138
  output_name = case relative_path.to_s
142
139
  when /\.html\.erb$/
@@ -148,7 +145,7 @@ class Html2SlimCLI < Thor
148
145
  else
149
146
  "#{relative_path}.slim"
150
147
  end
151
-
148
+
152
149
  Pathname.new(options[:target_dir]).join(output_name)
153
150
  else
154
151
  # Smart naming convention in place
@@ -182,7 +179,7 @@ class Html2SlimCLI < Thor
182
179
  end
183
180
 
184
181
  begin
185
- html_content = File.read(input_path)
182
+ html_content = File.read(input_path, encoding: 'UTF-8')
186
183
  slim_content = converter.convert(html_content)
187
184
 
188
185
  # Create backup if requested
@@ -195,16 +192,16 @@ class Html2SlimCLI < Thor
195
192
  output_path.dirname.mkpath
196
193
  # Ensure content ends with newline when writing to file
197
194
  slim_content += "\n" unless slim_content.end_with?("\n")
198
- File.write(output_path, slim_content)
195
+ File.write(output_path, slim_content, encoding: 'UTF-8')
199
196
 
200
197
  puts "Converted: #{input_path} -> #{output_path}"
201
-
198
+
202
199
  # Delete source file if requested (and not backing up)
203
200
  if options[:delete] && !options[:backup]
204
201
  File.delete(input_path)
205
202
  puts "Deleted: #{input_path}"
206
203
  end
207
-
204
+
208
205
  true
209
206
  rescue StandardError => e
210
207
  puts "Error converting #{input_path}: #{e.message}"