wysihtml5_gem 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "shoulda", ">= 0"
5
+ gem "rdoc", "~> 3.12"
6
+ gem "bundler", "~> 1.0.0"
7
+ gem "jeweler", "~> 1.8.4"
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.9)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ git (1.2.5)
8
+ i18n (0.6.1)
9
+ jeweler (1.8.4)
10
+ bundler (~> 1.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ rdoc
14
+ json (1.7.5)
15
+ multi_json (1.3.7)
16
+ rake (10.0.0)
17
+ rdoc (3.12)
18
+ json (~> 1.4)
19
+ shoulda (3.3.2)
20
+ shoulda-context (~> 1.0.1)
21
+ shoulda-matchers (~> 1.4.1)
22
+ shoulda-context (1.0.1)
23
+ shoulda-matchers (1.4.1)
24
+ activesupport (>= 3.0.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.0.0)
31
+ jeweler (~> 1.8.4)
32
+ rdoc (~> 3.12)
33
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 HouseKeeper
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # wysihtml5_gem
2
+ =============
3
+
4
+ A quick and simple gem to wrap and install wysihtml5 into a rails asset pipeline.
5
+ This gem will not create the tool bar, but this is very easily done and gives you all the flexibility
6
+ to add it yourself styling it anyway you like.
7
+
8
+ This gem is intended to be as clean as possible and versions of this gem will stay in line with versions of the wysihtml5
9
+
10
+ ## Installation for Rails 3.1 and above
11
+
12
+ Add the gem to your Gemfile
13
+
14
+ ``` ruby
15
+ gem 'wysihtml5_gem', '0.3.0'
16
+ ```
17
+
18
+ save and run bundle install.
19
+
20
+ ## Configuration into your rails application
21
+
22
+ In application.js add the following (I personally use coffescript)
23
+
24
+ ``` javascript
25
+ //= require wysihtml5_gem/wysihtml5-0.3.0
26
+ //= require wysihtml5_gem/advanced
27
+ ```
28
+
29
+ In application.css add the following (I use sass notation here)
30
+
31
+ ``` sass
32
+ @import "wysihtml5_gem/wysihtml5"
33
+ ```
34
+
35
+ Then just simple add the wysihtml5 class name to a text area and initialize wysihtml5 (I am using HAML notation here with a rails for helper)
36
+
37
+ ```haml
38
+ = text_area_tag :testing_wysihtml5, "", :class => "wysihtml5"
39
+ ```
40
+
41
+ or in pure html
42
+
43
+ ```html
44
+ <textarea id="testing_wysihtml5" class="wysihtml5"></textarea>
45
+ ```
46
+
47
+ the simple initialise the wysihtml5
48
+
49
+ ``` javascript
50
+ var editor = new wysihtml5.Editor("testing_wysihtml5", { // id of textarea element
51
+ //toolbar: "wysihtml5-toolbar", // id of toolbar element, which you need to create
52
+ parserRules: wysihtml5ParserRules // defined in parser rules set
53
+ });
54
+ ```
55
+
56
+ Copyright (c) 2012 HouseKeeper. See LICENSE.txt for
57
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "wysihtml5_gem"
18
+ gem.homepage = "http://github.com/housekeeper/wysihtml5_gem"
19
+ gem.license = "MIT"
20
+ gem.summary = "a quick a simple gem to wrap and install wysihtml5 into a rails gem so that its assets are served correctly"
21
+ gem.description = "a quick a simple gem to wrap and install wysihtml5 into a rails gem so that its assets are served correctly"
22
+ gem.email = "carl@house-keeping.com"
23
+ gem.authors = ["housekeeper"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "wysihtml5_gem #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -0,0 +1,553 @@
1
+ /**
2
+ * Full HTML5 compatibility rule set
3
+ * These rules define which tags and CSS classes are supported and which tags should be specially treated.
4
+ *
5
+ * Examples based on this rule set:
6
+ *
7
+ * <a href="http://foobar.com">foo</a>
8
+ * ... becomes ...
9
+ * <a href="http://foobar.com" target="_blank" rel="nofollow">foo</a>
10
+ *
11
+ * <img align="left" src="http://foobar.com/image.png">
12
+ * ... becomes ...
13
+ * <img class="wysiwyg-float-left" src="http://foobar.com/image.png" alt="">
14
+ *
15
+ * <div>foo<script>alert(document.cookie)</script></div>
16
+ * ... becomes ...
17
+ * <div>foo</div>
18
+ *
19
+ * <marquee>foo</marquee>
20
+ * ... becomes ...
21
+ * <span>foo</span>
22
+ *
23
+ * foo <br clear="both"> bar
24
+ * ... becomes ...
25
+ * foo <br class="wysiwyg-clear-both"> bar
26
+ *
27
+ * <div>hello <iframe src="http://google.com"></iframe></div>
28
+ * ... becomes ...
29
+ * <div>hello </div>
30
+ *
31
+ * <center>hello</center>
32
+ * ... becomes ...
33
+ * <div class="wysiwyg-text-align-center">hello</div>
34
+ */
35
+ var wysihtml5ParserRules = {
36
+ /**
37
+ * CSS Class white-list
38
+ * Following CSS classes won't be removed when parsed by the wysihtml5 HTML parser
39
+ */
40
+ "classes": {
41
+ "wysiwyg-clear-both": 1,
42
+ "wysiwyg-clear-left": 1,
43
+ "wysiwyg-clear-right": 1,
44
+ "wysiwyg-color-aqua": 1,
45
+ "wysiwyg-color-black": 1,
46
+ "wysiwyg-color-blue": 1,
47
+ "wysiwyg-color-fuchsia": 1,
48
+ "wysiwyg-color-gray": 1,
49
+ "wysiwyg-color-green": 1,
50
+ "wysiwyg-color-lime": 1,
51
+ "wysiwyg-color-maroon": 1,
52
+ "wysiwyg-color-navy": 1,
53
+ "wysiwyg-color-olive": 1,
54
+ "wysiwyg-color-purple": 1,
55
+ "wysiwyg-color-red": 1,
56
+ "wysiwyg-color-silver": 1,
57
+ "wysiwyg-color-teal": 1,
58
+ "wysiwyg-color-white": 1,
59
+ "wysiwyg-color-yellow": 1,
60
+ "wysiwyg-float-left": 1,
61
+ "wysiwyg-float-right": 1,
62
+ "wysiwyg-font-size-large": 1,
63
+ "wysiwyg-font-size-larger": 1,
64
+ "wysiwyg-font-size-medium": 1,
65
+ "wysiwyg-font-size-small": 1,
66
+ "wysiwyg-font-size-smaller": 1,
67
+ "wysiwyg-font-size-x-large": 1,
68
+ "wysiwyg-font-size-x-small": 1,
69
+ "wysiwyg-font-size-xx-large": 1,
70
+ "wysiwyg-font-size-xx-small": 1,
71
+ "wysiwyg-text-align-center": 1,
72
+ "wysiwyg-text-align-justify": 1,
73
+ "wysiwyg-text-align-left": 1,
74
+ "wysiwyg-text-align-right": 1
75
+ },
76
+ /**
77
+ * Tag list
78
+ *
79
+ * The following options are available:
80
+ *
81
+ * - add_class: converts and deletes the given HTML4 attribute (align, clear, ...) via the given method to a css class
82
+ * The following methods are implemented in wysihtml5.dom.parse:
83
+ * - align_text: converts align attribute values (right/left/center/justify) to their corresponding css class "wysiwyg-text-align-*")
84
+ * <p align="center">foo</p> ... becomes ... <p> class="wysiwyg-text-align-center">foo</p>
85
+ * - clear_br: converts clear attribute values left/right/all/both to their corresponding css class "wysiwyg-clear-*"
86
+ * <br clear="all"> ... becomes ... <br class="wysiwyg-clear-both">
87
+ * - align_img: converts align attribute values (right/left) on <img> to their corresponding css class "wysiwyg-float-*"
88
+ *
89
+ * - remove: removes the element and its content
90
+ *
91
+ * - rename_tag: renames the element to the given tag
92
+ *
93
+ * - set_class: adds the given class to the element (note: make sure that the class is in the "classes" white list above)
94
+ *
95
+ * - set_attributes: sets/overrides the given attributes
96
+ *
97
+ * - check_attributes: checks the given HTML attribute via the given method
98
+ * - url: allows only valid urls (starting with http:// or https://)
99
+ * - src: allows something like "/foobar.jpg", "http://google.com", ...
100
+ * - href: allows something like "mailto:bert@foo.com", "http://google.com", "/foobar.jpg"
101
+ * - alt: strips unwanted characters. if the attribute is not set, then it gets set (to ensure valid and compatible HTML)
102
+ * - numbers: ensures that the attribute only contains numeric characters
103
+ */
104
+ "tags": {
105
+ "tr": {
106
+ "add_class": {
107
+ "align": "align_text"
108
+ }
109
+ },
110
+ "strike": {
111
+ "remove": 1
112
+ },
113
+ "form": {
114
+ "rename_tag": "div"
115
+ },
116
+ "rt": {
117
+ "rename_tag": "span"
118
+ },
119
+ "code": {},
120
+ "acronym": {
121
+ "rename_tag": "span"
122
+ },
123
+ "br": {
124
+ "add_class": {
125
+ "clear": "clear_br"
126
+ }
127
+ },
128
+ "details": {
129
+ "rename_tag": "div"
130
+ },
131
+ "h4": {
132
+ "add_class": {
133
+ "align": "align_text"
134
+ }
135
+ },
136
+ "em": {},
137
+ "title": {
138
+ "remove": 1
139
+ },
140
+ "multicol": {
141
+ "rename_tag": "div"
142
+ },
143
+ "figure": {
144
+ "rename_tag": "div"
145
+ },
146
+ "xmp": {
147
+ "rename_tag": "span"
148
+ },
149
+ "small": {
150
+ "rename_tag": "span",
151
+ "set_class": "wysiwyg-font-size-smaller"
152
+ },
153
+ "area": {
154
+ "remove": 1
155
+ },
156
+ "time": {
157
+ "rename_tag": "span"
158
+ },
159
+ "dir": {
160
+ "rename_tag": "ul"
161
+ },
162
+ "bdi": {
163
+ "rename_tag": "span"
164
+ },
165
+ "command": {
166
+ "remove": 1
167
+ },
168
+ "ul": {},
169
+ "progress": {
170
+ "rename_tag": "span"
171
+ },
172
+ "dfn": {
173
+ "rename_tag": "span"
174
+ },
175
+ "iframe": {
176
+ "remove": 1
177
+ },
178
+ "figcaption": {
179
+ "rename_tag": "div"
180
+ },
181
+ "a": {
182
+ "check_attributes": {
183
+ "href": "url" // if you compiled master manually then change this from 'url' to 'href'
184
+ },
185
+ "set_attributes": {
186
+ "rel": "nofollow",
187
+ "target": "_blank"
188
+ }
189
+ },
190
+ "img": {
191
+ "check_attributes": {
192
+ "width": "numbers",
193
+ "alt": "alt",
194
+ "src": "url", // if you compiled master manually then change this from 'url' to 'src'
195
+ "height": "numbers"
196
+ },
197
+ "add_class": {
198
+ "align": "align_img"
199
+ }
200
+ },
201
+ "rb": {
202
+ "rename_tag": "span"
203
+ },
204
+ "footer": {
205
+ "rename_tag": "div"
206
+ },
207
+ "noframes": {
208
+ "remove": 1
209
+ },
210
+ "abbr": {
211
+ "rename_tag": "span"
212
+ },
213
+ "u": {},
214
+ "bgsound": {
215
+ "remove": 1
216
+ },
217
+ "sup": {
218
+ "rename_tag": "span"
219
+ },
220
+ "address": {
221
+ "rename_tag": "div"
222
+ },
223
+ "basefont": {
224
+ "remove": 1
225
+ },
226
+ "nav": {
227
+ "rename_tag": "div"
228
+ },
229
+ "h1": {
230
+ "add_class": {
231
+ "align": "align_text"
232
+ }
233
+ },
234
+ "head": {
235
+ "remove": 1
236
+ },
237
+ "tbody": {
238
+ "add_class": {
239
+ "align": "align_text"
240
+ }
241
+ },
242
+ "dd": {
243
+ "rename_tag": "div"
244
+ },
245
+ "s": {
246
+ "rename_tag": "span"
247
+ },
248
+ "li": {},
249
+ "td": {
250
+ "check_attributes": {
251
+ "rowspan": "numbers",
252
+ "colspan": "numbers"
253
+ },
254
+ "add_class": {
255
+ "align": "align_text"
256
+ }
257
+ },
258
+ "object": {
259
+ "remove": 1
260
+ },
261
+ "div": {
262
+ "add_class": {
263
+ "align": "align_text"
264
+ }
265
+ },
266
+ "option": {
267
+ "rename_tag": "span"
268
+ },
269
+ "select": {
270
+ "rename_tag": "span"
271
+ },
272
+ "i": {},
273
+ "track": {
274
+ "remove": 1
275
+ },
276
+ "wbr": {
277
+ "remove": 1
278
+ },
279
+ "fieldset": {
280
+ "rename_tag": "div"
281
+ },
282
+ "big": {
283
+ "rename_tag": "span",
284
+ "set_class": "wysiwyg-font-size-larger"
285
+ },
286
+ "button": {
287
+ "rename_tag": "span"
288
+ },
289
+ "noscript": {
290
+ "remove": 1
291
+ },
292
+ "svg": {
293
+ "remove": 1
294
+ },
295
+ "input": {
296
+ "remove": 1
297
+ },
298
+ "table": {},
299
+ "keygen": {
300
+ "remove": 1
301
+ },
302
+ "h5": {
303
+ "add_class": {
304
+ "align": "align_text"
305
+ }
306
+ },
307
+ "meta": {
308
+ "remove": 1
309
+ },
310
+ "map": {
311
+ "rename_tag": "div"
312
+ },
313
+ "isindex": {
314
+ "remove": 1
315
+ },
316
+ "mark": {
317
+ "rename_tag": "span"
318
+ },
319
+ "caption": {
320
+ "add_class": {
321
+ "align": "align_text"
322
+ }
323
+ },
324
+ "tfoot": {
325
+ "add_class": {
326
+ "align": "align_text"
327
+ }
328
+ },
329
+ "base": {
330
+ "remove": 1
331
+ },
332
+ "video": {
333
+ "remove": 1
334
+ },
335
+ "strong": {},
336
+ "canvas": {
337
+ "remove": 1
338
+ },
339
+ "output": {
340
+ "rename_tag": "span"
341
+ },
342
+ "marquee": {
343
+ "rename_tag": "span"
344
+ },
345
+ "b": {},
346
+ "q": {
347
+ "check_attributes": {
348
+ "cite": "url"
349
+ }
350
+ },
351
+ "applet": {
352
+ "remove": 1
353
+ },
354
+ "span": {},
355
+ "rp": {
356
+ "rename_tag": "span"
357
+ },
358
+ "spacer": {
359
+ "remove": 1
360
+ },
361
+ "source": {
362
+ "remove": 1
363
+ },
364
+ "aside": {
365
+ "rename_tag": "div"
366
+ },
367
+ "frame": {
368
+ "remove": 1
369
+ },
370
+ "section": {
371
+ "rename_tag": "div"
372
+ },
373
+ "body": {
374
+ "rename_tag": "div"
375
+ },
376
+ "ol": {},
377
+ "nobr": {
378
+ "rename_tag": "span"
379
+ },
380
+ "html": {
381
+ "rename_tag": "div"
382
+ },
383
+ "summary": {
384
+ "rename_tag": "span"
385
+ },
386
+ "var": {
387
+ "rename_tag": "span"
388
+ },
389
+ "del": {
390
+ "remove": 1
391
+ },
392
+ "blockquote": {
393
+ "check_attributes": {
394
+ "cite": "url"
395
+ }
396
+ },
397
+ "style": {
398
+ "remove": 1
399
+ },
400
+ "device": {
401
+ "remove": 1
402
+ },
403
+ "meter": {
404
+ "rename_tag": "span"
405
+ },
406
+ "h3": {
407
+ "add_class": {
408
+ "align": "align_text"
409
+ }
410
+ },
411
+ "textarea": {
412
+ "rename_tag": "span"
413
+ },
414
+ "embed": {
415
+ "remove": 1
416
+ },
417
+ "hgroup": {
418
+ "rename_tag": "div"
419
+ },
420
+ "font": {
421
+ "rename_tag": "span",
422
+ "add_class": {
423
+ "size": "size_font"
424
+ }
425
+ },
426
+ "tt": {
427
+ "rename_tag": "span"
428
+ },
429
+ "noembed": {
430
+ "remove": 1
431
+ },
432
+ "thead": {
433
+ "add_class": {
434
+ "align": "align_text"
435
+ }
436
+ },
437
+ "blink": {
438
+ "rename_tag": "span"
439
+ },
440
+ "plaintext": {
441
+ "rename_tag": "span"
442
+ },
443
+ "xml": {
444
+ "remove": 1
445
+ },
446
+ "h6": {
447
+ "add_class": {
448
+ "align": "align_text"
449
+ }
450
+ },
451
+ "param": {
452
+ "remove": 1
453
+ },
454
+ "th": {
455
+ "check_attributes": {
456
+ "rowspan": "numbers",
457
+ "colspan": "numbers"
458
+ },
459
+ "add_class": {
460
+ "align": "align_text"
461
+ }
462
+ },
463
+ "legend": {
464
+ "rename_tag": "span"
465
+ },
466
+ "hr": {},
467
+ "label": {
468
+ "rename_tag": "span"
469
+ },
470
+ "dl": {
471
+ "rename_tag": "div"
472
+ },
473
+ "kbd": {
474
+ "rename_tag": "span"
475
+ },
476
+ "listing": {
477
+ "rename_tag": "div"
478
+ },
479
+ "dt": {
480
+ "rename_tag": "span"
481
+ },
482
+ "nextid": {
483
+ "remove": 1
484
+ },
485
+ "pre": {},
486
+ "center": {
487
+ "rename_tag": "div",
488
+ "set_class": "wysiwyg-text-align-center"
489
+ },
490
+ "audio": {
491
+ "remove": 1
492
+ },
493
+ "datalist": {
494
+ "rename_tag": "span"
495
+ },
496
+ "samp": {
497
+ "rename_tag": "span"
498
+ },
499
+ "col": {
500
+ "remove": 1
501
+ },
502
+ "article": {
503
+ "rename_tag": "div"
504
+ },
505
+ "cite": {},
506
+ "link": {
507
+ "remove": 1
508
+ },
509
+ "script": {
510
+ "remove": 1
511
+ },
512
+ "bdo": {
513
+ "rename_tag": "span"
514
+ },
515
+ "menu": {
516
+ "rename_tag": "ul"
517
+ },
518
+ "colgroup": {
519
+ "remove": 1
520
+ },
521
+ "ruby": {
522
+ "rename_tag": "span"
523
+ },
524
+ "h2": {
525
+ "add_class": {
526
+ "align": "align_text"
527
+ }
528
+ },
529
+ "ins": {
530
+ "rename_tag": "span"
531
+ },
532
+ "p": {
533
+ "add_class": {
534
+ "align": "align_text"
535
+ }
536
+ },
537
+ "sub": {
538
+ "rename_tag": "span"
539
+ },
540
+ "comment": {
541
+ "remove": 1
542
+ },
543
+ "frameset": {
544
+ "remove": 1
545
+ },
546
+ "optgroup": {
547
+ "rename_tag": "span"
548
+ },
549
+ "header": {
550
+ "rename_tag": "div"
551
+ }
552
+ }
553
+ };