textutils 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +1 -0
- data/README.markdown +68 -3
- data/lib/textutils.rb +7 -2
- data/lib/textutils/filter/comment_filter.rb +60 -0
- metadata +4 -3
data/Manifest.txt
CHANGED
data/README.markdown
CHANGED
@@ -1,9 +1,73 @@
|
|
1
1
|
# `textutils` - Text Filters 'n' Helpers in Ruby
|
2
2
|
|
3
|
-
##
|
3
|
+
## Filters
|
4
|
+
|
5
|
+
### `comments_percent_style`
|
6
|
+
|
7
|
+
Strip comments lines starting with percent (that is, %). Example:
|
8
|
+
|
9
|
+
%%%%%%%%%%%%%%%%
|
10
|
+
% Some Headers
|
11
|
+
|
12
|
+
Title: Web Services REST-Style: Universal Identifiers, Formats & Protocols
|
13
|
+
|
14
|
+
%%%%%%%%%%%%%%%%%%%
|
15
|
+
% Some Extra CSS
|
16
|
+
|
17
|
+
table { width: 100%; }
|
18
|
+
table#restspeak th:nth-child(1) { width: 20%; }
|
19
|
+
table#restspeak th:nth-child(2) { width: 5%; }
|
20
|
+
|
21
|
+
Becomes
|
22
|
+
|
23
|
+
Title: Web Services REST-Style: Universal Identifiers, Formats & Protocols
|
24
|
+
|
25
|
+
table { width: 100%; }
|
26
|
+
table#restspeak th:nth-child(1) { width: 20%; }
|
27
|
+
table#restspeak th:nth-child(2) { width: 5%; }
|
28
|
+
|
29
|
+
Also supports multiline comments with `%begin`|`comment`|`comments`/`%end` pairs. Example:
|
30
|
+
|
31
|
+
%begin
|
32
|
+
Using modern browser such as Firefox, Chrome and Safari you can
|
33
|
+
now theme your slide shows using using "loss-free" vector graphics
|
34
|
+
in plain old CSS. Thanks to gradient support in backgrounds in CSS3.
|
35
|
+
%end
|
36
|
+
|
37
|
+
or
|
38
|
+
|
39
|
+
%comment
|
40
|
+
Using modern browser such as Firefox, Chrome and Safari you can
|
41
|
+
now theme your slide shows using using "loss-free" vector graphics
|
42
|
+
in plain old CSS. Thanks to gradient support in backgrounds in CSS3.
|
43
|
+
%end
|
44
|
+
|
45
|
+
Note: As a shortcut using a single `%end` directive (that is, without a matching `%begin`)
|
46
|
+
will skip everything until the end of the document.
|
47
|
+
|
48
|
+
|
49
|
+
### `skip_end_directive`
|
50
|
+
|
51
|
+
Skip/comment out blocks in your document by
|
52
|
+
enclosing with `__SKIP__`/`__END__`. Example:
|
53
|
+
|
54
|
+
__SKIP__
|
55
|
+
Using modern browser such as Firefox, Chrome and Safari you can
|
56
|
+
now theme your slide shows using using "loss-free" vector graphics
|
57
|
+
in plain old CSS. Thanks to gradient support in backgrounds in CSS3.
|
58
|
+
__END__
|
59
|
+
|
60
|
+
As a shortcut if you just use `__END__` (without `__SKIP__`) the filter
|
61
|
+
will skip everything from `__END__` until the end of the document.
|
62
|
+
|
4
63
|
|
5
64
|
TBD
|
6
65
|
|
66
|
+
## Helpers
|
67
|
+
|
68
|
+
TBD
|
69
|
+
|
70
|
+
|
7
71
|
## Install
|
8
72
|
|
9
73
|
Just install the gem:
|
@@ -15,9 +79,10 @@ Just install the gem:
|
|
15
79
|
|
16
80
|
The [`slideshow`](http://slideshow.rubyforge.org) (also known as Slide Show (S9)) gem
|
17
81
|
that lets you create slide shows
|
18
|
-
and author slides in plain text using a wiki-style markup language that's easy-to-write and easy-to-read
|
19
|
-
ships with the `props` gem.
|
82
|
+
and author slides in plain text using a wiki-style markup language that's easy-to-write and easy-to-read.
|
20
83
|
|
84
|
+
The [`markdown`](http://geraldb.github.com/markdown) gem that lets you use your markdown library
|
85
|
+
of choice.
|
21
86
|
|
22
87
|
## Alternatives
|
23
88
|
|
data/lib/textutils.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
module TextUtils
|
3
|
+
module Filter
|
4
|
+
|
5
|
+
def comments_percent_style( content, options={} )
|
6
|
+
|
7
|
+
# remove comments
|
8
|
+
# % comments
|
9
|
+
# %begin multiline comment
|
10
|
+
# %end multiline comment
|
11
|
+
|
12
|
+
# track statistics
|
13
|
+
comments_multi = 0
|
14
|
+
comments_single = 0
|
15
|
+
comments_end = 0
|
16
|
+
|
17
|
+
# remove multi-line comments
|
18
|
+
content.gsub!(/^%(begin|comment|comments).*?%end/m) do |match|
|
19
|
+
comments_multi += 1
|
20
|
+
""
|
21
|
+
end
|
22
|
+
|
23
|
+
# remove everyting starting w/ %end (note, can only be once in file)
|
24
|
+
content.sub!(/^%end.*/m) do |match|
|
25
|
+
comments_end += 1
|
26
|
+
""
|
27
|
+
end
|
28
|
+
|
29
|
+
# hack/note:
|
30
|
+
# note multi-line erb expressions/stmts might cause trouble
|
31
|
+
#
|
32
|
+
# %> gets escaped as special case (not treated as comment)
|
33
|
+
# <%
|
34
|
+
# whatever
|
35
|
+
# %> <!-- trouble here; would get removed as comment!
|
36
|
+
# todo: issue warning?
|
37
|
+
|
38
|
+
# remove single-line comments
|
39
|
+
content.gsub!(/(^%$)|(^%[^>].*)/ ) do |match|
|
40
|
+
comments_single += 1
|
41
|
+
""
|
42
|
+
end
|
43
|
+
|
44
|
+
puts " Removing %-comments (#{comments_single} lines, " +
|
45
|
+
"#{comments_multi} begin/end-blocks, #{comments_end} end-blocks)..."
|
46
|
+
|
47
|
+
content
|
48
|
+
end
|
49
|
+
|
50
|
+
def skip_end_directive( content, options={} )
|
51
|
+
# codex-style __SKIP__, __END__ directive
|
52
|
+
# ruby note: .*? is non-greedy (shortest-possible) regex match
|
53
|
+
content.gsub!(/__SKIP__.*?__END__/m, '')
|
54
|
+
content.sub!(/__END__.*/m, '')
|
55
|
+
content
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
end # module Filter
|
60
|
+
end # module TextUtils
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: textutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gerald Bauer
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- README.markdown
|
62
62
|
- Rakefile
|
63
63
|
- lib/textutils.rb
|
64
|
+
- lib/textutils/filter/comment_filter.rb
|
64
65
|
homepage: http://geraldb.github.com/textutils
|
65
66
|
licenses: []
|
66
67
|
|