blueprint-html2slim 1.1.0 → 1.3.1

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: bcd9f4a5d346b4edee89ff58f86e84501a642530ce563be68daca7ccaa4747e4
4
- data.tar.gz: b8d50860a181f7b4077be2aba82c520a5c3c0e498fed7b3c069e6e40077447ee
3
+ metadata.gz: 8659e98075970808c3f6b98f3bf5630df930b0164f4010cc57d2393a6646e403
4
+ data.tar.gz: cbae380fbe76e804e24d79ba393480864f9cdbd2858d4395d55f1527dacba5aa
5
5
  SHA512:
6
- metadata.gz: f53a93b08cb863037eadc43536bbdf5a551a58586d495254cfbfff181d2e0db1512f8a2533453a4c60b914b78ef5e7adfa3ce9fe3780c8ff3bd76c07ad0f388d
7
- data.tar.gz: d0206ced006d3113f391387223c77b96e958d1e6f6b5bafb44882badbd93eba8f75d786ba5a03d60787b873bb8bcb36ef05bf932f2b6c8c7a804d21e1f670382
6
+ metadata.gz: 85ee1ae5d5bc5ed1a67478c9255681fe3925141c575c29ae439abbfb77409b74002e881a12cbec444f2133659feaca90487012d44e8e73acbe1ac47ed7886458
7
+ data.tar.gz: 173c15886f0865772500f67cb04d06cfa425921fb0dc2fca77a0975003c6f8835ab013a3b78593dcf86824bba9899e22c5ddbb95b7b47168e2030bd248039379
data/CHANGELOG.md CHANGED
@@ -2,6 +2,86 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [1.3.1] - 2025-01-16
6
+
7
+ ### Fixed
8
+ - **SlimExtractor CSS Selector Support**:
9
+ - Fixed child combinator selectors (`body > section`) not working
10
+ - Now correctly extracts multiple matching elements instead of just the first
11
+ - Added support for parent-child relationship validation in selectors
12
+ - **Improved Content Extraction**:
13
+ - Enhanced default removal list to include `html`, `body`, `script` elements
14
+ - Added automatic cleanup of orphaned comments when sections are removed
15
+ - Fixed extraction logic to handle multiple sections properly
16
+ - **Enhanced CSS Selector Parser**:
17
+ - Added `parse_simple_selector()` for individual selector components
18
+ - Implemented `matches_child_selector()` for parent-child verification
19
+ - Added `find_parent_item()` for structure hierarchy navigation
20
+
21
+ ### Changed
22
+ - Default remove list now includes: `doctype html head nav header footer script body`
23
+ - CSS selector extraction now handles multiple matching elements in single operation
24
+ - Orphaned comments are automatically cleaned up during extraction
25
+
26
+ ## [1.3.0] - 2025-01-16
27
+
28
+ ### Added
29
+ - **SlimExtractor enhancements**:
30
+ - Extract outline up to specified depth (`--outline N`) for high-level structure analysis
31
+ - Extract fragments by CSS selector (`--selector`) supporting #id, .class, element, and combinations
32
+ - **Comprehensive documentation**:
33
+ - Complete README with detailed examples for all commands
34
+ - All command options now have descriptive help text
35
+ - Added workflow examples and use cases
36
+ - Table of contents for easy navigation
37
+
38
+ ### Changed
39
+ - Improved command-line help system with detailed option descriptions
40
+ - Fixed extraction logic bug where keep/remove functionality wasn't working correctly
41
+ - Enhanced help output with categorized examples
42
+
43
+ ### Fixed
44
+ - SlimExtractor now correctly handles keep/remove section logic
45
+ - Thor deprecation warnings resolved with `exit_on_failure?` method
46
+ - RuboCop style violations corrected
47
+
48
+ ## [1.2.0] - 2025-01-16
49
+
50
+ ### Added
51
+ - New `slimtool` command-line utility for comprehensive Slim template manipulation
52
+ - **SlimFixer**: Automatically fixes common Slim syntax issues
53
+ - Fixes text starting with "/" that would be interpreted as comments (converts to pipe notation)
54
+ - Fixes multiline text blocks using proper pipe notation
55
+ - Supports backup and dry-run modes
56
+ - **SlimExtractor**: Extract or remove specific sections from Slim templates
57
+ - Remove unwanted sections (doctype, head, nav, footer, script, etc.)
58
+ - Keep only specified sections (main, article, or any element/class/id)
59
+ - Remove outer wrapper elements
60
+ - Extract outline up to specified depth (high-level structure only)
61
+ - Extract fragments by CSS selector (#id, .class, element, element.class#id)
62
+ - Custom output file support
63
+ - **SlimValidator**: Validate Slim syntax and check for potential issues
64
+ - Detects syntax errors (invalid indentation, unclosed brackets, empty Ruby markers)
65
+ - Strict mode: checks for tabs, inline styles, long lines
66
+ - Rails mode: checks for hardcoded URLs, static assets, missing CSRF tokens
67
+ - Comprehensive error and warning reporting
68
+ - **SlimRailsifier**: Convert static templates to Rails conventions
69
+ - Configurable link mappings via JSON/YAML files (no automatic guessing)
70
+ - Convert CDN assets to Rails asset pipeline helpers
71
+ - Add CSRF protection meta tags to forms
72
+ - Supports dry-run and backup modes
73
+ - **LinkExtractor**: Extract and analyze hardcoded links from templates
74
+ - Find all static HTML links, forms, assets, and images
75
+ - Categorize link types and suggest Rails helper conversions
76
+ - Multiple output formats (JSON, YAML, text)
77
+ - Batch processing of multiple files
78
+ - Comprehensive test suite for all new SlimTool features
79
+
80
+ ### Changed
81
+ - Updated gem to include both `html2slim` and `slimtool` executables
82
+ - Rails link conversions now require explicit mappings (removed automatic fallback guessing)
83
+ - Improved command-line help with detailed examples and option descriptions
84
+
5
85
  ## [1.1.0] - 2025-01-16
6
86
 
7
87
  ### Added
@@ -23,10 +103,16 @@ All notable changes to this project will be documented in this file.
23
103
 
24
104
  ### Added
25
105
  - Initial release of blueprint-html2slim
26
- - HTML to Slim conversion
27
- - ERB template support
28
- - Smart file naming conventions
106
+ - HTML to Slim conversion with full HTML5 support
107
+ - ERB template support with proper Ruby code handling
108
+ - Smart file naming conventions (.html → .html.slim, .erb → .slim)
29
109
  - Backup option for source files
30
110
  - Recursive directory processing
31
- - Dry-run mode
32
- - Custom output path support
111
+ - Dry-run mode for previewing conversions
112
+ - Custom output path support
113
+ - Force overwrite option
114
+ - Delete source files after conversion
115
+ - Target directory support with structure preservation
116
+ - Custom indentation size support
117
+ - Comprehensive test suite with RSpec
118
+ - RuboCop integration for code quality
data/README.md CHANGED
@@ -1,9 +1,19 @@
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
4
 
5
5
  **Online Converter**: Try the web-based version at [https://railsblueprint.com/html2slim](https://railsblueprint.com/html2slim)
6
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)
16
+
7
17
  ## Requirements
8
18
 
9
19
  - Ruby 2.7 - 3.4 (compatible with latest Ruby versions)
@@ -28,7 +38,13 @@ Or install it yourself as:
28
38
  gem install blueprint-html2slim
29
39
  ```
30
40
 
31
- ## 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
32
48
 
33
49
  ### Programmatic Usage (Ruby)
34
50
 
@@ -62,77 +78,386 @@ converter = Blueprint::Html2Slim::Converter.new(indent_size: 4)
62
78
 
63
79
  ### Command Line Usage
64
80
 
65
- Convert a single file:
81
+ #### Basic Conversion
82
+
66
83
  ```bash
84
+ # Convert a single file
67
85
  html2slim index.html
68
86
  # Creates: index.html.slim
69
- ```
70
87
 
71
- Convert with custom output:
72
- ```bash
88
+ # Convert with custom output
73
89
  html2slim -o custom.slim index.html
74
- ```
75
90
 
76
- Convert multiple files:
77
- ```bash
91
+ # Convert multiple files
78
92
  html2slim file1.html file2.erb file3.html.erb
79
93
  ```
80
94
 
81
- Convert and backup original files:
95
+ #### File Management Options
96
+
82
97
  ```bash
98
+ # Create backup of original files
83
99
  html2slim -b index.html
84
100
  # Creates: index.html.slim
85
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
86
109
  ```
87
110
 
88
- Convert files in a directory recursively:
111
+ #### Directory Processing
112
+
89
113
  ```bash
114
+ # Convert files in a directory recursively
90
115
  html2slim -r ./views
91
- ```
92
116
 
93
- Convert to target directory (preserves structure):
94
- ```bash
117
+ # Convert to target directory (preserves structure)
95
118
  html2slim -t dist/ -r src/
96
119
  # Converts src/views/index.html to dist/views/index.html.slim
97
120
  ```
98
121
 
99
- Delete source files after conversion:
100
- ```bash
101
- html2slim -d old_templates/*.erb
102
- # Converts and deletes the original .erb files
103
- ```
122
+ #### Preview and Testing
104
123
 
105
- Dry run (preview what would be converted):
106
124
  ```bash
125
+ # Dry run (preview what would be converted)
107
126
  html2slim -n file.html
127
+
128
+ # Custom indentation (default: 2 spaces)
129
+ html2slim -i 4 template.html
108
130
  ```
109
131
 
110
- ## Naming Convention
132
+ ### Naming Conventions
111
133
 
112
134
  - `file.html` → `file.html.slim`
113
135
  - `file.html.erb` → `file.html.slim`
114
136
  - `file.erb` → `file.slim`
115
137
 
116
- ## Options
138
+ ### All HTML2Slim Options
117
139
 
118
- - `-o, --output FILE` - Output file path (only for single file conversion)
140
+ - `-o, --output FILE` - Output file path (single file only)
119
141
  - `-r, --recursive` - Process directories recursively
120
- - `-n, --dry-run` - Show what would be converted without actually converting
142
+ - `-n, --dry-run` - Preview conversions without modifying files
121
143
  - `-d, --delete` - Delete source files after successful conversion
122
- - `-t, --target-dir DIR` - Target directory for converted files (preserves directory structure)
144
+ - `-t, --target-dir DIR` - Target directory for converted files
123
145
  - `-f, --force` - Overwrite existing files without prompting
124
- - `-b, --backup` - Backup source files with .bak extension
146
+ - `-b, --backup` - Create .bak backup of source files
125
147
  - `-i, --indent SIZE` - Indentation size in spaces (default: 2)
126
148
  - `-h, --help` - Show help message
127
149
  - `-v, --version` - Show version
128
150
 
129
- ## 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
130
462
 
131
- - Converts HTML tags to Slim syntax
132
- - Handles HTML attributes, IDs, and classes
133
- - Preserves ERB tags (<%= %> and <% %>)
134
- - Supports nested elements
135
- - Handles void elements correctly
136
- - Preserves comments
137
- - Smart output file naming
138
- - Optional source file backup
463
+ This gem is available as open source under the terms of the [MIT License](LICENSE).