sassafras 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.
@@ -0,0 +1,298 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
4
+ <head>
5
+ <title>Sassafras Swatch</title>
6
+ <meta http-equiv="content-type" content="text/xhtml; charset=utf-8" />
7
+ <meta http-equiv="imagetoolbar" content="no" />
8
+ <meta name="distribution" content="all" />
9
+ <meta name="robots" content="all" />
10
+ <meta name="resource-type" content="document" />
11
+ <meta name="MSSmartTagsPreventParsing" content="true" />
12
+ <style type="text/css">
13
+ body {
14
+ font-family: Helvetica, Verdana, Sans-serif;
15
+ text-align: center;
16
+ }
17
+ .container {
18
+ width: 600px;
19
+ }
20
+ th {
21
+ text-align: left;
22
+ }
23
+ td.swatch {
24
+ width: 10em;
25
+ }
26
+ td.hex {
27
+ font-family: "Courier New", Fixed;
28
+ }
29
+ pre {
30
+ text-align: left;
31
+ }
32
+ </style>
33
+ </head>
34
+ <body>
35
+ <div align="center">
36
+ <div class="container">
37
+ <h1>Sassafras</h1>
38
+ <table width="100%">
39
+
40
+ <tr>
41
+ <th colspan="3">complement1</td>
42
+ </tr>
43
+
44
+ <tr>
45
+ <td>
46
+ dark
47
+ </td>
48
+ <td class="hex">
49
+ #80002b
50
+ </td>
51
+ <td class="swatch" style="background-color: #80002b;">&nbsp;</td>
52
+ </tr>
53
+
54
+ <tr>
55
+ <td>
56
+ darker
57
+ </td>
58
+ <td class="hex">
59
+ #4d001a
60
+ </td>
61
+ <td class="swatch" style="background-color: #4d001a;">&nbsp;</td>
62
+ </tr>
63
+
64
+ <tr>
65
+ <td>
66
+ light
67
+ </td>
68
+ <td class="hex">
69
+ #ff80aa
70
+ </td>
71
+ <td class="swatch" style="background-color: #ff80aa;">&nbsp;</td>
72
+ </tr>
73
+
74
+ <tr>
75
+ <td>
76
+ lightest
77
+ </td>
78
+ <td class="hex">
79
+ #ffe6ee
80
+ </td>
81
+ <td class="swatch" style="background-color: #ffe6ee;">&nbsp;</td>
82
+ </tr>
83
+
84
+ <tr>
85
+ <td>
86
+ lighter
87
+ </td>
88
+ <td class="hex">
89
+ #ffb3cc
90
+ </td>
91
+ <td class="swatch" style="background-color: #ffb3cc;">&nbsp;</td>
92
+ </tr>
93
+
94
+ <tr>
95
+ <td>
96
+ mid
97
+ </td>
98
+ <td class="hex">
99
+ #ff0055
100
+ </td>
101
+ <td class="swatch" style="background-color: #ff0055;">&nbsp;</td>
102
+ </tr>
103
+
104
+ <tr>
105
+ <td>
106
+ darkest
107
+ </td>
108
+ <td class="hex">
109
+ #1a0009
110
+ </td>
111
+ <td class="swatch" style="background-color: #1a0009;">&nbsp;</td>
112
+ </tr>
113
+
114
+
115
+ <tr>
116
+ <th colspan="3">complement2</td>
117
+ </tr>
118
+
119
+ <tr>
120
+ <td>
121
+ dark
122
+ </td>
123
+ <td class="hex">
124
+ #00802b
125
+ </td>
126
+ <td class="swatch" style="background-color: #00802b;">&nbsp;</td>
127
+ </tr>
128
+
129
+ <tr>
130
+ <td>
131
+ darker
132
+ </td>
133
+ <td class="hex">
134
+ #004d1a
135
+ </td>
136
+ <td class="swatch" style="background-color: #004d1a;">&nbsp;</td>
137
+ </tr>
138
+
139
+ <tr>
140
+ <td>
141
+ light
142
+ </td>
143
+ <td class="hex">
144
+ #80ffaa
145
+ </td>
146
+ <td class="swatch" style="background-color: #80ffaa;">&nbsp;</td>
147
+ </tr>
148
+
149
+ <tr>
150
+ <td>
151
+ lightest
152
+ </td>
153
+ <td class="hex">
154
+ #e6ffee
155
+ </td>
156
+ <td class="swatch" style="background-color: #e6ffee;">&nbsp;</td>
157
+ </tr>
158
+
159
+ <tr>
160
+ <td>
161
+ lighter
162
+ </td>
163
+ <td class="hex">
164
+ #b3ffcc
165
+ </td>
166
+ <td class="swatch" style="background-color: #b3ffcc;">&nbsp;</td>
167
+ </tr>
168
+
169
+ <tr>
170
+ <td>
171
+ mid
172
+ </td>
173
+ <td class="hex">
174
+ #00ff55
175
+ </td>
176
+ <td class="swatch" style="background-color: #00ff55;">&nbsp;</td>
177
+ </tr>
178
+
179
+ <tr>
180
+ <td>
181
+ darkest
182
+ </td>
183
+ <td class="hex">
184
+ #001a09
185
+ </td>
186
+ <td class="swatch" style="background-color: #001a09;">&nbsp;</td>
187
+ </tr>
188
+
189
+
190
+ <tr>
191
+ <th colspan="3">base</td>
192
+ </tr>
193
+
194
+ <tr>
195
+ <td>
196
+ dark
197
+ </td>
198
+ <td class="hex">
199
+ #000080
200
+ </td>
201
+ <td class="swatch" style="background-color: #000080;">&nbsp;</td>
202
+ </tr>
203
+
204
+ <tr>
205
+ <td>
206
+ darker
207
+ </td>
208
+ <td class="hex">
209
+ #00004d
210
+ </td>
211
+ <td class="swatch" style="background-color: #00004d;">&nbsp;</td>
212
+ </tr>
213
+
214
+ <tr>
215
+ <td>
216
+ light
217
+ </td>
218
+ <td class="hex">
219
+ #8080ff
220
+ </td>
221
+ <td class="swatch" style="background-color: #8080ff;">&nbsp;</td>
222
+ </tr>
223
+
224
+ <tr>
225
+ <td>
226
+ lightest
227
+ </td>
228
+ <td class="hex">
229
+ #e6e6ff
230
+ </td>
231
+ <td class="swatch" style="background-color: #e6e6ff;">&nbsp;</td>
232
+ </tr>
233
+
234
+ <tr>
235
+ <td>
236
+ lighter
237
+ </td>
238
+ <td class="hex">
239
+ #b3b3ff
240
+ </td>
241
+ <td class="swatch" style="background-color: #b3b3ff;">&nbsp;</td>
242
+ </tr>
243
+
244
+ <tr>
245
+ <td>
246
+ mid
247
+ </td>
248
+ <td class="hex">
249
+ #0000ff
250
+ </td>
251
+ <td class="swatch" style="background-color: #0000ff;">&nbsp;</td>
252
+ </tr>
253
+
254
+ <tr>
255
+ <td>
256
+ darkest
257
+ </td>
258
+ <td class="hex">
259
+ #00001a
260
+ </td>
261
+ <td class="swatch" style="background-color: #00001a;">&nbsp;</td>
262
+ </tr>
263
+
264
+
265
+ </table>
266
+ <pre># Generated by Sassafras
267
+ # complement1
268
+ !complement1_dark = #80002b
269
+ !complement1_darker = #4d001a
270
+ !complement1_light = #ff80aa
271
+ !complement1_lightest = #ffe6ee
272
+ !complement1_lighter = #ffb3cc
273
+ !complement1_mid = #ff0055
274
+ !complement1_darkest = #1a0009
275
+
276
+ # complement2
277
+ !complement2_dark = #00802b
278
+ !complement2_darker = #004d1a
279
+ !complement2_light = #80ffaa
280
+ !complement2_lightest = #e6ffee
281
+ !complement2_lighter = #b3ffcc
282
+ !complement2_mid = #00ff55
283
+ !complement2_darkest = #001a09
284
+
285
+ # base
286
+ !base_dark = #000080
287
+ !base_darker = #00004d
288
+ !base_light = #8080ff
289
+ !base_lightest = #e6e6ff
290
+ !base_lighter = #b3b3ff
291
+ !base_mid = #0000ff
292
+ !base_darkest = #00001a
293
+
294
+ </pre>
295
+ </div>
296
+ </div>
297
+ </body>
298
+ </html>
@@ -0,0 +1,241 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'rubygems'
5
+
6
+ require File.dirname(__FILE__) + '/sassafras/version'
7
+
8
+ gem 'color-tools'
9
+ require 'color'
10
+
11
+ gem 'activesupport'
12
+ require 'activesupport'
13
+
14
+ require 'erb'
15
+
16
+ module Sassafras
17
+
18
+ class Theme
19
+
20
+ attr_reader :base_rgb
21
+
22
+ class << self
23
+ def create(type, base)
24
+ Theme.send(type, base)
25
+ end
26
+
27
+ def colors
28
+ @colors
29
+ end
30
+
31
+ def basic(base)
32
+ BasicTheme.new(base)
33
+ end
34
+
35
+ def complementary(base)
36
+ ComplementaryTheme.new(base)
37
+ end
38
+
39
+ def analogous(base)
40
+ AnalogousTheme.new(base)
41
+ end
42
+
43
+ def triadic(base)
44
+ TriadicTheme.new(base)
45
+ end
46
+
47
+ def split_complementary(base)
48
+ SplitComplementaryTheme.new(base)
49
+ end
50
+
51
+ def rectangle(base)
52
+ RectangleTheme.new(base)
53
+ end
54
+
55
+ def square(base)
56
+ SquareTheme.new(base)
57
+ end
58
+ end
59
+
60
+ def initialize(base)
61
+ is_hex = (base =~ /#.*/)
62
+ @base_rgb = is_hex ? Color::RGB.from_html(base) : Color::RGB.const_get(base.to_s.camelize)
63
+ @colors = { 'base' =>
64
+ Tints.new(@base_rgb).colors.merge(
65
+ Shades.new(@base_rgb).colors)
66
+ }
67
+ return unless self.class.colors
68
+ self.class.colors.each do |name, steps|
69
+ color = self.hue_adjusted_base_rgb(steps)
70
+ @colors[name] =
71
+ Tints. new(color).colors.merge(
72
+ Shades.new(color).colors)
73
+ end
74
+ end
75
+
76
+ def base
77
+ @base_rgb.html
78
+ end
79
+
80
+ def colors(name=nil)
81
+ return @colors[name.to_s] if name
82
+ @colors
83
+ end
84
+
85
+ def sass
86
+ returning "# Generated by Sassafras\n" do |str|
87
+ colors.each do |set, colors|
88
+ str << "# #{set}\n"
89
+ colors.each do |name, hex|
90
+ str << "!#{set}_#{name} = #{hex}\n"
91
+ end
92
+ str << "\n"
93
+ end
94
+ end
95
+ end
96
+
97
+ def get_binding; binding; end
98
+
99
+ protected
100
+
101
+ def hue_adjusted_base_rgb(steps)
102
+ one_step = 0.0555555555555
103
+
104
+ hue = base_rgb.to_hsl.h
105
+ sat = base_rgb.to_hsl.s
106
+ lum = base_rgb.to_hsl.l
107
+
108
+ hue += one_step * steps
109
+ if hue > 1.0
110
+ hue -= 1.0
111
+ elsif hue < 0.0
112
+ hue += 1.0
113
+ end
114
+
115
+ Color::HSL.from_fraction(hue, sat, lum).to_rgb
116
+ end
117
+
118
+ def self.color(name, block)
119
+ instance_eval do
120
+ @colors ||= {}
121
+ @colors[name] = block
122
+ end
123
+ end
124
+
125
+ end
126
+
127
+ class ColorSet
128
+
129
+ def initialize(base_rgb, prefix=nil)
130
+ @rgb = base_rgb
131
+ @prefix = prefix
132
+ @colors = {}
133
+ end
134
+
135
+ def colors
136
+ returning Hash.new do |hash|
137
+ @colors.each do |name, hex|
138
+ if @prefix
139
+ hash["#{@prefix}_#{name}"] = hex
140
+ else
141
+ hash[name] = hex
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ def method_missing(method, *args)
148
+ return @colors[method.to_s] if @colors[method.to_s]
149
+ super
150
+ end
151
+
152
+ end
153
+
154
+
155
+ class Tints < ColorSet
156
+
157
+ def initialize(base_rgb, prefix=nil)
158
+ super(base_rgb, prefix)
159
+ @colors = {
160
+ 'mid' => @rgb.html,
161
+ 'light' => @rgb.lighten_by(50).html,
162
+ 'lighter' => @rgb.lighten_by(30).html,
163
+ 'lightest' => @rgb.lighten_by(10).html
164
+ }
165
+ end
166
+
167
+ end
168
+
169
+ class Shades < ColorSet
170
+
171
+ def initialize(base_rgb, prefix=nil)
172
+ super(base_rgb, prefix)
173
+ @colors = {
174
+ 'mid' => @rgb.html,
175
+ 'dark' => @rgb.darken_by(50).html,
176
+ 'darker' => @rgb.darken_by(30).html,
177
+ 'darkest' => @rgb.darken_by(10).html
178
+ }
179
+ end
180
+
181
+ end
182
+
183
+ class BasicTheme < Theme
184
+
185
+ end
186
+
187
+ class ComplementaryTheme < Theme
188
+
189
+ color 'complementary', +6
190
+
191
+ end
192
+
193
+ class AnalogousTheme < Theme
194
+
195
+ color 'support', -1
196
+ color 'accent', +1
197
+
198
+ end
199
+
200
+ class TriadicTheme < Theme
201
+
202
+ color 'accent1', +4
203
+ color 'accent2', -4
204
+
205
+ end
206
+
207
+ class SplitComplementaryTheme < Theme
208
+
209
+ color 'complement1', +5
210
+ color 'complement2', -5
211
+
212
+ end
213
+
214
+ class RectangleTheme < Theme
215
+
216
+ color 'accent1', +2
217
+ color 'accent2', +6
218
+ color 'accent3', -4
219
+
220
+ end
221
+
222
+ class SquareTheme < Theme
223
+
224
+ color 'accent1', +3
225
+ color 'complement', +6
226
+ color 'accent2', +9
227
+
228
+ end
229
+
230
+ class HTMLSwatch
231
+
232
+ def initialize(theme)
233
+ @theme = theme
234
+ File.open(File.dirname(__FILE__) + '/sassafras/swatch.html.erb') do |f|
235
+ erb = ERB.new(f.read)
236
+ erb.result(@theme.get_binding)
237
+ end
238
+ end
239
+ end
240
+
241
+ end