document 1.0.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.
- data/README +183 -0
- data/lib/document.rb +29 -0
- data/spec/document_spec.rb +21 -0
- metadata +55 -0
data/README
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
= RedCloth - Textile parser for Ruby
|
|
2
|
+
|
|
3
|
+
Homepage:: http://redcloth.org
|
|
4
|
+
Author:: Jason Garber
|
|
5
|
+
Copyright:: (c) 2009 Jason Garber
|
|
6
|
+
License:: MIT
|
|
7
|
+
|
|
8
|
+
(See http://redcloth.org/textile/ for a Textile reference.)
|
|
9
|
+
|
|
10
|
+
= RedCloth
|
|
11
|
+
|
|
12
|
+
RedCloth is a Ruby library for converting Textile into HTML.
|
|
13
|
+
|
|
14
|
+
== Installing
|
|
15
|
+
|
|
16
|
+
RedCloth can be installed via RubyGems:
|
|
17
|
+
|
|
18
|
+
gem install RedCloth
|
|
19
|
+
|
|
20
|
+
It will install the appropriate Ruby, JRuby, or Win32 gem. If using JRuby,
|
|
21
|
+
version 1.1.5 or greater is required.
|
|
22
|
+
|
|
23
|
+
== Compiling
|
|
24
|
+
|
|
25
|
+
If you just want to use RedCloth, you do NOT need to build/compile it. It is
|
|
26
|
+
compiled from C sources automatically when you install the gem on the ruby
|
|
27
|
+
platform. Precompiled binary gems are provided for JRuby and Win32 platforms.
|
|
28
|
+
|
|
29
|
+
RedCloth can be compiled with <tt>rake compile</tt>. Ragel 6.3 or greater and
|
|
30
|
+
the echoe gem are needed to build, compile, and package RedCloth. Again, Ragel
|
|
31
|
+
and echoe are NOT needed to simply use RedCloth.
|
|
32
|
+
|
|
33
|
+
=== Supported platforms
|
|
34
|
+
|
|
35
|
+
By default, the rake compile task builds a native C Ruby extension that works
|
|
36
|
+
with Ruby 1.8 or 1.9. You can cross-compile for JRuby 1.3 with rake java
|
|
37
|
+
compile and for Win32 with rake mingw compile. A pure Ruby version can be
|
|
38
|
+
generated with rake pureruby compile, but the parser it produces is slow and
|
|
39
|
+
incompatible with Ruby 1.9. The JRuby and pure-Ruby extensions don't support
|
|
40
|
+
multi-byte characters. The RedCloth::EXTENSION_LANGUAGE constant indicates in
|
|
41
|
+
which language your copy of RedCloth is compiled.
|
|
42
|
+
|
|
43
|
+
== Using RedCloth
|
|
44
|
+
|
|
45
|
+
RedCloth is simply an extension of the String class, which can handle
|
|
46
|
+
Textile formatting. Use it like a String and output HTML with its
|
|
47
|
+
RedCloth#to_html method.
|
|
48
|
+
|
|
49
|
+
Simple use:
|
|
50
|
+
text = "This is *my* text."
|
|
51
|
+
RedCloth.new(text).to_html
|
|
52
|
+
|
|
53
|
+
Multi-line example:
|
|
54
|
+
|
|
55
|
+
doc = RedCloth.new <<EOD
|
|
56
|
+
h2. Test document
|
|
57
|
+
|
|
58
|
+
Just a simple test.
|
|
59
|
+
EOD
|
|
60
|
+
puts doc.to_html
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
== What is Textile?
|
|
64
|
+
|
|
65
|
+
Textile is a simple formatting style for text
|
|
66
|
+
documents, loosely based on some HTML conventions.
|
|
67
|
+
|
|
68
|
+
== Sample Textile Text
|
|
69
|
+
|
|
70
|
+
h2. This is a title
|
|
71
|
+
|
|
72
|
+
h3. This is a subhead
|
|
73
|
+
|
|
74
|
+
This is a bit of paragraph.
|
|
75
|
+
|
|
76
|
+
bq. This is a blockquote.
|
|
77
|
+
|
|
78
|
+
= Writing Textile
|
|
79
|
+
|
|
80
|
+
A Textile document consists of paragraphs. Paragraphs
|
|
81
|
+
can be specially formatted by adding a small instruction
|
|
82
|
+
to the beginning of the paragraph.
|
|
83
|
+
|
|
84
|
+
h3. Header 3.
|
|
85
|
+
bq. Blockquote.
|
|
86
|
+
# Numeric list.
|
|
87
|
+
* Bulleted list.
|
|
88
|
+
|
|
89
|
+
== Quick Phrase Modifiers
|
|
90
|
+
|
|
91
|
+
Quick phrase modifiers are also included, to allow formatting
|
|
92
|
+
of small portions of text within a paragraph.
|
|
93
|
+
|
|
94
|
+
_emphasis_
|
|
95
|
+
__italicized__
|
|
96
|
+
*strong*
|
|
97
|
+
**bold**
|
|
98
|
+
??citation??
|
|
99
|
+
-deleted text-
|
|
100
|
+
+inserted text+
|
|
101
|
+
^superscript^
|
|
102
|
+
~subscript~
|
|
103
|
+
@code@
|
|
104
|
+
%(classname)span%
|
|
105
|
+
|
|
106
|
+
==notextile== (leave text alone)
|
|
107
|
+
|
|
108
|
+
== Links
|
|
109
|
+
|
|
110
|
+
To make a hypertext link, put the link text in "quotation
|
|
111
|
+
marks" followed immediately by a colon and the URL of the link.
|
|
112
|
+
|
|
113
|
+
Optional: text in (parentheses) following the link text,
|
|
114
|
+
but before the closing quotation mark, will become a title
|
|
115
|
+
attribute for the link, visible as a tool tip when a cursor is above it.
|
|
116
|
+
|
|
117
|
+
Example:
|
|
118
|
+
|
|
119
|
+
"This is a link (This is a title)":http://www.textism.com
|
|
120
|
+
|
|
121
|
+
Will become:
|
|
122
|
+
|
|
123
|
+
<a href="http://www.textism.com" title="This is a title">This is a link</a>
|
|
124
|
+
|
|
125
|
+
== Images
|
|
126
|
+
|
|
127
|
+
To insert an image, put the URL for the image inside exclamation marks.
|
|
128
|
+
|
|
129
|
+
Optional: text that immediately follows the URL in (parentheses) will
|
|
130
|
+
be used as the Alt text for the image. Images on the web should always
|
|
131
|
+
have descriptive Alt text for the benefit of readers using non-graphical
|
|
132
|
+
browsers.
|
|
133
|
+
|
|
134
|
+
Optional: place a colon followed by a URL immediately after the
|
|
135
|
+
closing ! to make the image into a link.
|
|
136
|
+
|
|
137
|
+
Example:
|
|
138
|
+
|
|
139
|
+
!http://www.textism.com/common/textist.gif(Textist)!
|
|
140
|
+
|
|
141
|
+
Will become:
|
|
142
|
+
|
|
143
|
+
<img src="http://www.textism.com/common/textist.gif" alt="Textist" />
|
|
144
|
+
|
|
145
|
+
With a link:
|
|
146
|
+
|
|
147
|
+
!/common/textist.gif(Textist)!:http://textism.com
|
|
148
|
+
|
|
149
|
+
Will become:
|
|
150
|
+
|
|
151
|
+
<a href="http://textism.com"><img src="/common/textist.gif" alt="Textist" /></a>
|
|
152
|
+
|
|
153
|
+
== Defining Acronyms
|
|
154
|
+
|
|
155
|
+
HTML allows authors to define acronyms via the tag. The definition appears as a
|
|
156
|
+
tool tip when a cursor hovers over the acronym. A crucial aid to clear writing,
|
|
157
|
+
this should be used at least once for each acronym in documents where they appear.
|
|
158
|
+
|
|
159
|
+
To quickly define an acronym in Textile, place the full text in (parentheses)
|
|
160
|
+
immediately following the acronym.
|
|
161
|
+
|
|
162
|
+
Example:
|
|
163
|
+
|
|
164
|
+
ACLU(American Civil Liberties Union)
|
|
165
|
+
|
|
166
|
+
Will become:
|
|
167
|
+
|
|
168
|
+
<acronym title="American Civil Liberties Union">ACLU</acronym>
|
|
169
|
+
|
|
170
|
+
== Adding Tables
|
|
171
|
+
|
|
172
|
+
In Textile, simple tables can be added by separating each column by
|
|
173
|
+
a pipe.
|
|
174
|
+
|
|
175
|
+
|a|simple|table|row|
|
|
176
|
+
|And|Another|table|row|
|
|
177
|
+
|
|
178
|
+
Styles are applied with curly braces.
|
|
179
|
+
|
|
180
|
+
table{border:1px solid black}.
|
|
181
|
+
{background:#ddd;color:red}. |a|red|row|
|
|
182
|
+
|
|
183
|
+
|
data/lib/document.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
class Document
|
|
4
|
+
|
|
5
|
+
attr_accessor :title, :author, :content
|
|
6
|
+
|
|
7
|
+
def initialize( title, author, content )
|
|
8
|
+
@title = title
|
|
9
|
+
@author = author
|
|
10
|
+
@content = content
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def words
|
|
14
|
+
@content.split
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def word_count
|
|
18
|
+
words.size
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def average_word_length
|
|
22
|
+
number_word_characters / word_count
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def number_word_characters
|
|
26
|
+
words.inject( 0 ) { |total, word| total += word.size }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
$: << "#{File.dirname(__FILE__)}/../lib"
|
|
2
|
+
|
|
3
|
+
require 'document'
|
|
4
|
+
|
|
5
|
+
describe Document do
|
|
6
|
+
|
|
7
|
+
before :each do
|
|
8
|
+
@document = Document.new( 'test', 'russ', 'nothing' )
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should hold onto the title, author and content" do
|
|
12
|
+
@document.title.should == 'test'
|
|
13
|
+
@document.author.should == 'russ'
|
|
14
|
+
@document.content.should == 'nothing'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should be able to split content into words" do
|
|
18
|
+
@document.content = 'the rain in spain'
|
|
19
|
+
@document.words.should == %w{ the rain in spain }
|
|
20
|
+
end
|
|
21
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: document
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Russ Olsen
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2010-01-01 00:00:00 -05:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Document - Simple document class
|
|
17
|
+
email: russ@russolsen.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- README
|
|
26
|
+
- lib/document.rb
|
|
27
|
+
- spec/document_spec.rb
|
|
28
|
+
has_rdoc: true
|
|
29
|
+
homepage: http://www.russolsen.com
|
|
30
|
+
post_install_message:
|
|
31
|
+
rdoc_options: []
|
|
32
|
+
|
|
33
|
+
require_paths:
|
|
34
|
+
- lib
|
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: "0"
|
|
40
|
+
version:
|
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: "0"
|
|
46
|
+
version:
|
|
47
|
+
requirements: []
|
|
48
|
+
|
|
49
|
+
rubyforge_project: simple_document
|
|
50
|
+
rubygems_version: 1.3.1
|
|
51
|
+
signing_key:
|
|
52
|
+
specification_version: 2
|
|
53
|
+
summary: Document - Simple document class
|
|
54
|
+
test_files: []
|
|
55
|
+
|