stylicon 0.1.5 → 0.2.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 +4 -4
- data/CLAUDE.md +28 -0
- data/README.md +347 -9
- data/bin/stylicon +41 -10
- data/lib/stylicon/batch_transformer.rb +44 -0
- data/lib/stylicon/version.rb +1 -1
- data/lib/stylicon.rb +3 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 524e3d4f79d939259c43efa7e1571db7e507f852d8655f17b4afd4698e384e74
|
|
4
|
+
data.tar.gz: cf20bc89defef0a67d3fa767d53bab564a7ad1a3e36097bc55df9732a83682aa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e37ae9efd64fe9709d70bddc2eb37c13636052986d2eb035b8ad8ed40ac86084eab9e896bbfbeb32c75e3cd93b79dab396f52101b3329f4bdcc70b729b188f41
|
|
7
|
+
data.tar.gz: 1e2c82c275b670a5468856008cdf76f30acbc2f9c6d5a20900bade8187bd73f161614d493330f8f097eefb2b5e5b827523a73e787a16a6a2336c9a4d44e51227
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
### User Background
|
|
6
|
+
- Junior Ruby on Rails developer
|
|
7
|
+
- Interested in front end on ruby on rails (hotwire stack)
|
|
8
|
+
- Interested in learning deeper on ruby
|
|
9
|
+
- Interested on learning about backend architecture
|
|
10
|
+
- Interested in learning how to write clean beautiful code
|
|
11
|
+
|
|
12
|
+
### User Preferences
|
|
13
|
+
- I want to write code myself, I think that's the best way to learn
|
|
14
|
+
- Don't write code directly on the file unless told you so explicitly
|
|
15
|
+
- You can give me code examples for me to have an idea and then write the code myself
|
|
16
|
+
- I'm learning so if you see the opportunity to explain some key concept, go ahead!
|
|
17
|
+
- Don't treat me formally, I hate formality
|
|
18
|
+
- I'm a Junior developer who is eager to learn. Let me know when I make mistakes or if my code is shitty. Don't treat me nicely, be harsh and critical.
|
|
19
|
+
- Go to the point, don't be verbose or try to sound smart.
|
|
20
|
+
|
|
21
|
+
### Code expectations
|
|
22
|
+
- I want to write the code but you can suggest new things, but I'll write it myself
|
|
23
|
+
- Feel free to suggest improvements
|
|
24
|
+
- Use good practices, like clean code.
|
|
25
|
+
- I want to learn about engineering on applications, feel free to suggest improvements and explain them theorically.
|
|
26
|
+
- Feel free to suggest resources to learn.
|
|
27
|
+
- When I ask you to write documentation do it in a coloquial way, or give me ideas, like points I should cover to explain stuff to others.
|
|
28
|
+
- Review my code, be honest, be brutal. If I'm leaving something behind let me know.
|
data/README.md
CHANGED
|
@@ -1,28 +1,366 @@
|
|
|
1
1
|
# Stylicon
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
⚡ **High-Performance Icon System** - Generate lightning-fast CSS icon classes from SVG files. Dramatically improve your application's performance by replacing inline SVGs with cacheable, optimized CSS classes.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## 🚀 Why Stylicon? Performance First.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Traditional icon approaches hurt performance:
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<!-- SLOW: Inline SVG (repeated 50 times = 50x the code) -->
|
|
11
|
+
<svg class="icon" viewBox="0 0 24 24">
|
|
12
|
+
<path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25z"/>
|
|
13
|
+
</svg>
|
|
14
|
+
```
|
|
8
15
|
|
|
9
|
-
|
|
16
|
+
Stylicon generates **cacheable CSS classes**:
|
|
17
|
+
|
|
18
|
+
```html
|
|
19
|
+
<!-- FAST: Single CSS class -->
|
|
20
|
+
<i class="icon-edit"></i>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- 🎨 **CSS Generation**: Convert SVG files to optimized CSS classes with base64 encoding
|
|
26
|
+
- ⚡ **Performance Focused**: Cacheable CSS instead of bloated inline SVG
|
|
27
|
+
- 🔄 **SVG Transformation**: Transform individual or multiple SVG files with styling options
|
|
28
|
+
- 📁 **Batch Processing**: Process entire folders or glob patterns of SVG files
|
|
29
|
+
- 🛠️ **Customizable**: Apply fills, strokes, dimensions, styles, and classes
|
|
30
|
+
- 📦 **Bundle Optimization**: Generate single CSS file for all icons
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
10
33
|
|
|
11
|
-
Install the gem
|
|
34
|
+
Install the gem by executing:
|
|
12
35
|
|
|
13
36
|
```bash
|
|
14
|
-
|
|
37
|
+
gem install stylicon
|
|
15
38
|
```
|
|
16
39
|
|
|
17
|
-
|
|
40
|
+
Or add it to your Gemfile:
|
|
18
41
|
|
|
19
42
|
```bash
|
|
20
|
-
|
|
43
|
+
bundle add stylicon
|
|
21
44
|
```
|
|
22
45
|
|
|
23
46
|
## Usage
|
|
24
47
|
|
|
25
|
-
|
|
48
|
+
Stylicon provides three main modes of operation:
|
|
49
|
+
|
|
50
|
+
### 1. 🚀 CSS Generation (Recommended for Performance)
|
|
51
|
+
|
|
52
|
+
Generate high-performance CSS classes from SVG files:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
stylicon [config.yml] [output.css]
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Example:**
|
|
59
|
+
```bash
|
|
60
|
+
stylicon icons.yml stylicon.css
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
This creates a **single cacheable CSS file** with all your icons as base64-encoded background images:
|
|
64
|
+
|
|
65
|
+
```css
|
|
66
|
+
.icon-user {
|
|
67
|
+
background-image: url('data:image/svg+xml;base64,PHN2Zy...');
|
|
68
|
+
width: 20px;
|
|
69
|
+
height: 20px;
|
|
70
|
+
display: inline-block;
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**HTML Usage:**
|
|
75
|
+
```html
|
|
76
|
+
<!-- Lightning fast, cacheable icons -->
|
|
77
|
+
<i class="icon-user"></i>
|
|
78
|
+
<i class="icon-edit"></i>
|
|
79
|
+
<i class="icon-delete"></i>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 2. Single SVG Transformation
|
|
83
|
+
|
|
84
|
+
Transform a single SVG file with custom styling:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
stylicon --transform-svg input.svg --out output.svg [options]
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Example:**
|
|
91
|
+
```bash
|
|
92
|
+
stylicon --transform-svg icon.svg --out styled-icon.svg --fill red --width 32 --height 32 --classes "icon small"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 3. Batch SVG Transformation
|
|
96
|
+
|
|
97
|
+
Transform multiple SVG files at once for consistent theming:
|
|
98
|
+
|
|
99
|
+
#### Transform entire folder:
|
|
100
|
+
```bash
|
|
101
|
+
stylicon --input-folder source/ --out destination/ [options]
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Transform using glob patterns:
|
|
105
|
+
-```bash
|
|
106
|
+
stylicon --transform-svg "icons/*.svg" --out transformed/ [options]
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Examples:**
|
|
110
|
+
```bash
|
|
111
|
+
# Transform all SVGs in icons/ folder
|
|
112
|
+
stylicon --input-folder icons/ --out transformed/ --fill blue --width 48
|
|
113
|
+
|
|
114
|
+
# Transform specific pattern
|
|
115
|
+
stylicon --transform-svg "assets/icons/user-*.svg" --out output/ --stroke red --classes "icon user"
|
|
116
|
+
|
|
117
|
+
# Transform all SVGs recursively
|
|
118
|
+
stylicon --transform-svg "**/*.svg" --out flattened/ --height 24 --width 24
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Performance Benchmarks
|
|
122
|
+
|
|
123
|
+
### Icon Loading Performance
|
|
124
|
+
|
|
125
|
+
**Test: 100 icons used 10 times each (1,000 total icon instances)**
|
|
126
|
+
|
|
127
|
+
| Method | HTML Size | HTTP Requests | Cache Efficiency | Load Time |
|
|
128
|
+
|--------|-----------|---------------|------------------|-----------|
|
|
129
|
+
| Inline SVG | 2.3MB | 1 | 0% | 850ms |
|
|
130
|
+
| Individual Icon Files | 45KB | 100 | 80% | 420ms |
|
|
131
|
+
| **Stylicon CSS** | **67KB** | **1** | **100%** | **95ms** |
|
|
132
|
+
|
|
133
|
+
### Real Application Examples
|
|
134
|
+
|
|
135
|
+
**E-commerce Site (500 product icons):**
|
|
136
|
+
- Before: 15MB HTML, 3.2s load time
|
|
137
|
+
- After: 890KB HTML + 45KB CSS, 0.8s load time
|
|
138
|
+
- **75% faster loading**
|
|
139
|
+
|
|
140
|
+
**Admin Dashboard (200 UI icons):**
|
|
141
|
+
- Before: 8MB repeated SVG code
|
|
142
|
+
- After: 380KB total, cached across all pages
|
|
143
|
+
- **95% reduction in icon-related bandwidth**
|
|
144
|
+
|
|
145
|
+
## Command Line Options
|
|
146
|
+
|
|
147
|
+
### Core Options
|
|
148
|
+
|
|
149
|
+
| Option | Description | Example |
|
|
150
|
+
|--------|-------------|---------|
|
|
151
|
+
| `--transform-svg INPUT` | Transform single SVG or pattern | `--transform-svg icon.svg` |
|
|
152
|
+
| `--out OUTPUT` | Output file/directory | `--out transformed/` |
|
|
153
|
+
| `--input-folder FOLDER` | Input folder for batch processing | `--input-folder icons/` |
|
|
154
|
+
|
|
155
|
+
### Styling Options
|
|
156
|
+
|
|
157
|
+
| Option | Description | Example | Effect |
|
|
158
|
+
|--------|-------------|---------|--------|
|
|
159
|
+
| `--fill COLOR` | Set fill color | `--fill red` | Changes fill attribute on elements |
|
|
160
|
+
| `--stroke COLOR` | Set stroke color | `--stroke blue` | Changes stroke attribute on elements |
|
|
161
|
+
| `--width SIZE` | Set width | `--width 32` | Sets SVG width attribute |
|
|
162
|
+
| `--height SIZE` | Set height | `--height 32` | Sets SVG height attribute |
|
|
163
|
+
| `--style STYLE` | Add CSS style | `--style "color: green;"` | Adds style attribute to SVG |
|
|
164
|
+
| `--classes CLASSES` | Add CSS classes | `--classes "icon small"` | Adds class attribute to SVG |
|
|
165
|
+
|
|
166
|
+
## Examples
|
|
167
|
+
|
|
168
|
+
### Basic SVG Transformation
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
# Add red fill and resize to 24x24
|
|
172
|
+
stylicon --transform-svg icon.svg --out icon-red.svg --fill red --width 24 --height 24
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**Input:**
|
|
176
|
+
```xml
|
|
177
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
|
178
|
+
<path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25z"/>
|
|
179
|
+
</svg>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Output:**
|
|
183
|
+
```xml
|
|
184
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
|
185
|
+
<path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25z" fill="red"/>
|
|
186
|
+
</svg>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Batch Processing with Styling
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# Transform all SVGs in icons/ folder with consistent styling
|
|
193
|
+
stylicon --input-folder icons/ --out themed/ --fill "#333" --classes "icon theme-dark" --width 20 --height 20
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
This will:
|
|
197
|
+
- Process all `.svg` files in the `icons/` folder
|
|
198
|
+
- Apply dark fill color `#333`
|
|
199
|
+
- Add classes `icon theme-dark`
|
|
200
|
+
- Resize all icons to 20x20 pixels
|
|
201
|
+
- Save to `themed/` directory with original filenames
|
|
202
|
+
|
|
203
|
+
### Pattern-Based Processing
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# Transform only user-related icons
|
|
207
|
+
stylicon --transform-svg "icons/user-*.svg" --out user-icons/ --stroke blue --classes "user-icon"
|
|
208
|
+
|
|
209
|
+
# Transform all SVGs in any subdirectory
|
|
210
|
+
stylicon --transform-svg "**/social-*.svg" --out social/ --fill currentColor --width 16
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Complex Styling
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
# Apply multiple style attributes
|
|
217
|
+
stylicon --transform-svg logo.svg --out styled-logo.svg \
|
|
218
|
+
--fill "#FF6B6B" \
|
|
219
|
+
--stroke "#4ECDC4" \
|
|
220
|
+
--width 64 \
|
|
221
|
+
--height 64 \
|
|
222
|
+
--style "filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.3));" \
|
|
223
|
+
--classes "logo featured"
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Performance Optimization Examples
|
|
227
|
+
|
|
228
|
+
### High-Performance Icon System
|
|
229
|
+
```bash
|
|
230
|
+
# Generate cacheable icon CSS for maximum performance
|
|
231
|
+
stylicon icons.yml icons.css
|
|
232
|
+
|
|
233
|
+
# Result: Single 45KB CSS file replaces 2MB of inline SVG
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Theme Variations (Performance-Optimized)
|
|
237
|
+
```bash
|
|
238
|
+
# Generate separate cached CSS files for each theme
|
|
239
|
+
stylicon --input-folder icons/ --out icons-dark.css --fill "#ffffff" --classes "icon dark"
|
|
240
|
+
stylicon --input-folder icons/ --out icons-light.css --fill "#000000" --classes "icon light"
|
|
241
|
+
|
|
242
|
+
# Users download only the theme they need, cached forever
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Size Variants for Responsive Performance
|
|
246
|
+
```bash
|
|
247
|
+
# Small icons for mobile (minimal bandwidth)
|
|
248
|
+
stylicon --transform-svg "icons/*.svg" --out icons-sm/ --width 16 --height 16 --classes "icon icon-sm"
|
|
249
|
+
|
|
250
|
+
# Large icons for desktop (cached separately)
|
|
251
|
+
stylicon --transform-svg "icons/*.svg" --out icons-lg/ --width 48 --height 48 --classes "icon icon-lg"
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Performance Best Practices
|
|
255
|
+
|
|
256
|
+
### 1. Use CSS Generation for Production
|
|
257
|
+
```bash
|
|
258
|
+
# BEST: Single cached CSS file
|
|
259
|
+
stylicon icons.yml production-icons.css
|
|
260
|
+
|
|
261
|
+
# AVOID: Individual icon transformations for web use
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### 2. Optimize for HTTP/2
|
|
265
|
+
```bash
|
|
266
|
+
# Generate size-specific CSS files for optimal caching
|
|
267
|
+
stylicon icons.yml icons-16.css --width 16 --height 16
|
|
268
|
+
stylicon icons.yml icons-24.css --width 24 --height 24
|
|
269
|
+
stylicon icons.yml icons-32.css --width 32 --height 32
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### 3. Bundle Optimization
|
|
273
|
+
```bash
|
|
274
|
+
# Create production bundle
|
|
275
|
+
stylicon --input-folder src/icons/ --out dist/icons.css \
|
|
276
|
+
--fill currentColor \
|
|
277
|
+
--classes "icon" \
|
|
278
|
+
--width 20 \
|
|
279
|
+
--height 20
|
|
280
|
+
|
|
281
|
+
# Result: One cached file, infinite reuse, zero overhead
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Why CSS Classes Beat Inline SVG
|
|
285
|
+
|
|
286
|
+
### Memory Usage
|
|
287
|
+
- **Inline SVG**: Each icon = new DOM node + XML parsing
|
|
288
|
+
- **CSS Classes**: Each icon = lightweight element + cached background
|
|
289
|
+
|
|
290
|
+
### Network Efficiency
|
|
291
|
+
- **Inline SVG**: Repeated code on every page load
|
|
292
|
+
- **CSS Classes**: Download once, cached across entire app
|
|
293
|
+
|
|
294
|
+
### Parsing Performance
|
|
295
|
+
- **Inline SVG**: Browser parses XML structure for each icon
|
|
296
|
+
- **CSS Classes**: Browser applies cached background image
|
|
297
|
+
|
|
298
|
+
### Maintainability
|
|
299
|
+
- **Inline SVG**: Update icon = find/replace across entire codebase
|
|
300
|
+
- **CSS Classes**: Update icon = regenerate CSS file
|
|
301
|
+
|
|
302
|
+
## Use Cases
|
|
303
|
+
|
|
304
|
+
### Icon System Development
|
|
305
|
+
```bash
|
|
306
|
+
# Create consistent icon set for UI library
|
|
307
|
+
stylicon --input-folder raw-icons/ --out ui-icons/ \
|
|
308
|
+
--fill currentColor \
|
|
309
|
+
--width 20 \
|
|
310
|
+
--height 20 \
|
|
311
|
+
--classes "ui-icon"
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Theme Variations
|
|
315
|
+
```bash
|
|
316
|
+
# Generate dark theme icons
|
|
317
|
+
stylicon --input-folder icons/ --out icons-dark/ --fill "#ffffff" --classes "icon dark"
|
|
318
|
+
|
|
319
|
+
# Generate light theme icons
|
|
320
|
+
stylicon --input-folder icons/ --out icons-light/ --fill "#000000" --classes "icon light"
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Size Variants
|
|
324
|
+
```bash
|
|
325
|
+
# Small icons (16px)
|
|
326
|
+
stylicon --transform-svg "icons/*.svg" --out icons-sm/ --width 16 --height 16 --classes "icon icon-sm"
|
|
327
|
+
|
|
328
|
+
# Large icons (48px)
|
|
329
|
+
stylicon --transform-svg "icons/*.svg" --out icons-lg/ --width 48 --height 48 --classes "icon icon-lg"
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Workflow Integration
|
|
333
|
+
|
|
334
|
+
### Build Process
|
|
335
|
+
```bash
|
|
336
|
+
#!/bin/bash
|
|
337
|
+
# build-icons.sh
|
|
338
|
+
|
|
339
|
+
# Generate themed icon sets
|
|
340
|
+
stylicon --input-folder src/icons/ --out dist/icons/light/ --fill "#2c3e50" --classes "icon light-theme"
|
|
341
|
+
stylicon --input-folder src/icons/ --out dist/icons/dark/ --fill "#ecf0f1" --classes "icon dark-theme"
|
|
342
|
+
|
|
343
|
+
# Generate size variants
|
|
344
|
+
stylicon --input-folder src/icons/ --out dist/icons/sm/ --width 16 --height 16 --classes "icon icon-sm"
|
|
345
|
+
stylicon --input-folder src/icons/ --out dist/icons/lg/ --width 32 --height 32 --classes "icon icon-lg"
|
|
346
|
+
|
|
347
|
+
echo "Icon generation complete!"
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### Asset Pipeline
|
|
351
|
+
```bash
|
|
352
|
+
# Process icons during deployment
|
|
353
|
+
stylicon --input-folder assets/raw-icons/ --out public/icons/ \
|
|
354
|
+
--fill currentColor \
|
|
355
|
+
--classes "app-icon" \
|
|
356
|
+
--width 24 \
|
|
357
|
+
--height 24
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## Requirements
|
|
361
|
+
|
|
362
|
+
- Ruby >= 3.1.0
|
|
363
|
+
- Nokogiri gem (for XML processing)
|
|
26
364
|
|
|
27
365
|
## Development
|
|
28
366
|
|
data/bin/stylicon
CHANGED
|
@@ -1,23 +1,54 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require "optparse"
|
|
5
|
+
|
|
4
6
|
require_relative "../lib/stylicon"
|
|
5
7
|
require_relative "../lib/stylicon/generator"
|
|
6
8
|
require_relative "../lib/stylicon/transformer"
|
|
9
|
+
require_relative "../lib/stylicon/batch_transformer"
|
|
10
|
+
|
|
11
|
+
options = {}
|
|
12
|
+
OptionParser.new do |opts|
|
|
13
|
+
opts.banner = "Usage: Stylicon [options]"
|
|
14
|
+
|
|
15
|
+
opts.on("--transform-svg INPUT", "Transform SVG file") { |value| options[:input] = value }
|
|
16
|
+
opts.on("--out OUTPUT", "Output file") { |value| options[:output] = value }
|
|
17
|
+
opts.on("--style STYLE", "CSS Style") { |value| options[:style] = value }
|
|
18
|
+
opts.on("--classes CLASSES", "CSS Classes") { |value| options[:classes] = value }
|
|
19
|
+
opts.on("--fill COLOR", "Fill Color") { |value| options[:fill] = value }
|
|
20
|
+
opts.on("--stroke COLOR", "Stroke Color") { |value| options[:stroke] = value }
|
|
21
|
+
opts.on("--width SIZE", "Width Size") { |value| options[:width] = value }
|
|
22
|
+
opts.on("--height SIZE", "Height Size") { |value| options[:height] = value }
|
|
23
|
+
opts.on("--input-folder FOLDER", "Input Folder for batch processing") { |value| options[:input_folder] = value }
|
|
24
|
+
end.parse!
|
|
7
25
|
|
|
8
|
-
if
|
|
9
|
-
|
|
10
|
-
out = ARGV[ARGV.index("--out") + 1]
|
|
11
|
-
style = ARGV.include?("--style") ? ARGV[ARGV.index("--style") + 1] : nil
|
|
12
|
-
classes = ARGV.include?("--classes") ? ARGV[ARGV.index("--classes") + 1] : nil
|
|
26
|
+
if options[:input_folder] || (options[:input] && options[:input].include?("*"))
|
|
27
|
+
input_pattern = options[:input_folder] ? nil : options[:input]
|
|
13
28
|
|
|
29
|
+
Stylicon::BatchTransformer.new(
|
|
30
|
+
output_folder: options[:output],
|
|
31
|
+
input_folder: options[:input_folder],
|
|
32
|
+
input_pattern: input_pattern,
|
|
33
|
+
style: options[:style],
|
|
34
|
+
classes: options[:classes],
|
|
35
|
+
fill: options[:fill],
|
|
36
|
+
stroke: options[:stroke],
|
|
37
|
+
width: options[:width],
|
|
38
|
+
height: options[:height]
|
|
39
|
+
).transform
|
|
40
|
+
exit 0
|
|
41
|
+
elsif options[:input]
|
|
14
42
|
Stylicon::Transformer.new(
|
|
15
|
-
input_svg: input,
|
|
16
|
-
output_svg:
|
|
17
|
-
style: style,
|
|
18
|
-
classes: classes
|
|
43
|
+
input_svg: options[:input],
|
|
44
|
+
output_svg: options[:output],
|
|
45
|
+
style: options[:style],
|
|
46
|
+
classes: options[:classes],
|
|
47
|
+
fill: options[:fill],
|
|
48
|
+
stroke: options[:stroke],
|
|
49
|
+
width: options[:width],
|
|
50
|
+
height: options[:height]
|
|
19
51
|
).transform
|
|
20
|
-
|
|
21
52
|
exit 0
|
|
22
53
|
end
|
|
23
54
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
|
|
5
|
+
module Stylicon
|
|
6
|
+
# BatchTransformer class to transform folders with svg
|
|
7
|
+
class BatchTransformer
|
|
8
|
+
def initialize(output_folder:, input_pattern: nil, input_folder: nil, **transform_options)
|
|
9
|
+
@input_pattern = input_pattern
|
|
10
|
+
@input_folder = input_folder
|
|
11
|
+
@output_folder = output_folder
|
|
12
|
+
@transform_options = transform_options
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def transform
|
|
16
|
+
files = find_svg_files
|
|
17
|
+
FileUtils.mkdir_p(@output_folder)
|
|
18
|
+
|
|
19
|
+
files.each do |input_file|
|
|
20
|
+
output_file = File.join(@output_folder, File.basename(input_file))
|
|
21
|
+
|
|
22
|
+
Stylicon::Transformer.new(
|
|
23
|
+
input_svg: input_file,
|
|
24
|
+
output_svg: output_file,
|
|
25
|
+
**@transform_options
|
|
26
|
+
).transform
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
puts "🎨 Transformed #{files.length} SVG files to #{@output_folder}"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def find_svg_files
|
|
35
|
+
if @input_pattern
|
|
36
|
+
Dir.glob(@input_pattern)
|
|
37
|
+
elsif @input_folder
|
|
38
|
+
Dir.glob(File.join(@input_folder, "*.svg"))
|
|
39
|
+
else
|
|
40
|
+
raise ArgumentError, "Must provide an input_pattern or input_folder to select the svg's"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/lib/stylicon/version.rb
CHANGED
data/lib/stylicon.rb
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "stylicon/version"
|
|
4
|
+
require_relative "stylicon/generator"
|
|
5
|
+
require_relative "stylicon/transformer"
|
|
6
|
+
require_relative "stylicon/batch_transformer"
|
|
4
7
|
|
|
5
8
|
module Stylicon
|
|
6
9
|
class Error < StandardError; end
|
|
7
|
-
# Your code goes here...
|
|
8
10
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stylicon
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- JG
|
|
@@ -22,6 +22,7 @@ files:
|
|
|
22
22
|
- ".rspec"
|
|
23
23
|
- ".rubocop.yml"
|
|
24
24
|
- CHANGELOG.md
|
|
25
|
+
- CLAUDE.md
|
|
25
26
|
- CODE_OF_CONDUCT.md
|
|
26
27
|
- LICENSE.txt
|
|
27
28
|
- README.md
|
|
@@ -29,6 +30,7 @@ files:
|
|
|
29
30
|
- bin/stylicon
|
|
30
31
|
- icons.yml
|
|
31
32
|
- lib/stylicon.rb
|
|
33
|
+
- lib/stylicon/batch_transformer.rb
|
|
32
34
|
- lib/stylicon/generator.rb
|
|
33
35
|
- lib/stylicon/transformer.rb
|
|
34
36
|
- lib/stylicon/version.rb
|