wbzyl-rack-codehighlighter 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,31 +1,116 @@
1
1
  # Rack Middleware for Code Highlighting
2
2
 
3
- The *Codehighlighter* gem provides a thin interface over a bunch
4
- of exisitng code highlighters to make their usage as generic possible.
3
+ Why one should use middleware (filter) for code highlighting?
4
+ The short answer is: because it is unobtrusive.
5
+
6
+ In pre-Rack applications era the possible approaches were:
7
+
8
+ 1. pure javascript
9
+
10
+ [*Ruby tips from me, your idol*](http://www.binarylogic.com/2009/04/19/ruby-tips-from-me-your-idol):
11
+ I can not tell you how much time I’ve wasted trying to add in some
12
+ cool feature into rails. I would dig into the rails internals,
13
+ override methods, do all kinds of tricky stuff. I thought I was
14
+ awesome. A month later rails comes out with some cool new feature, I
15
+ update rails and everything explodes.
16
+
17
+ 2. gems (ok) + conection (obtrusive)
18
+
5
19
 
6
20
  To install it, run:
7
21
 
8
22
  sudo gem install wbzyl-rack-codehighlighter -s http://gems.github.com
9
23
 
24
+ Analyze
25
+ [Syntax Highlighting](http://ruby-toolbox.com/categories/syntax_highlighting.html)
26
+ packages from the *The Ruby Toolbox* page.
27
+
28
+ Exisitng practice is obtrusive:
29
+
30
+ http://carboni.ca/projects/harsh/
31
+ unless HAML is used
32
+ http://redclothcoderay.rubyforge.org/
33
+ http://github.com/augustl/redcloth-with-coderay
34
+ how to use with Rails
35
+ does't degrade to html: new source tag
36
+ http://github.com/arya/tm_syntax_highlighting/
37
+ how to connect to rails/sinatra?
38
+
39
+ Pure Javascript highlighters:
40
+
41
+ In Ruby on Rails (redcloth)
42
+
43
+ Add censored method/example.
44
+
45
+
46
+
47
+
48
+ ## Using with Rack application
49
+
50
+ *Rack::Codehighlighter* can be used with any Rack application, for example with
51
+ a **Sinatra** application. If your application includes a rackup file or
52
+ uses *Rack::Builder* to construct the application pipeline, simply
53
+ require and use as follows:
54
+
55
+ gem 'wbzyl-rack-codehighlighter'
56
+ require 'rack/codehighlighter'
57
+
58
+ gem 'ultraviolet'
59
+ require 'uv'
60
+
61
+ use Rack::Codehighlighter, :ultraviolet
62
+ run app
63
+
64
+ Instead of *ultraviolet* you can use other supported highlighters:
65
+ *syntax*, *coderay*, *prettify*.
66
+
67
+ Include in the layout one of provided stylesheets.
68
+
69
+ ## Using with Rails
70
+
71
+ In order to use include the following in a Rails application
72
+ `config/environment.rb` file:
73
+
74
+ require 'rack/codehighlighter'
75
+
76
+ Rails::Initializer.run do |config|
77
+ config.gem 'wbzyl-rack-codehighlighter'
78
+ config.middleware.use Rack::Codehighlighter, :ultraviolet
79
+ end
80
+
81
+ Check the Rack configuration:
82
+
83
+ rake middleware
84
+
85
+ More configuration options: see below.
86
+
87
+
88
+ [*Ruby tips from me, your idol*](http://www.binarylogic.com/2009/04/19/ruby-tips-from-me-your-idol):
89
+ Think about what you are doing, try to understand it, come up with a
90
+ better solution, etc.
91
+ *Is it Rack a cool feature?*
92
+
93
+
94
+ ## Configuration options
95
+
10
96
  Markup your code with:
11
97
 
12
98
  <pre><code>:::ruby
13
99
  ...
14
100
  </code></pre>
15
101
 
102
+ ## Quick Sinatra example
103
+
16
104
  Example (incomplete html, needs a layout file with link to css):
17
105
 
18
- # file simple.rb
106
+ # file example.rb
19
107
 
20
108
  require 'rubygems'
21
109
  require 'sinatra'
22
110
 
23
111
  gem 'coderay'
24
- require 'coderay' # use the Coderay highlighter
112
+ require 'coderay'
25
113
 
26
- gem 'wbzyl-sinatra-rdiscount'
27
- require 'sinatra/rdiscount'
28
-
29
114
  gem 'wbzyl-rack-codehighlighter'
30
115
  require 'rack/codehighlighter'
31
116
 
@@ -50,20 +135,19 @@ Example (incomplete html, needs a layout file with link to css):
50
135
  end
51
136
  </code></pre>
52
137
 
53
- ## An example
138
+ Run the above example with:
139
+
140
+ ruby example.rb
141
+
54
142
 
55
- The Codehighlighter follows the same syntax as regular Markdown
56
- code blocks, with one exception. It needs to know what
57
- language to use for the code block.
143
+ ## More Sinatra examples
144
+
145
+ The default markup:
58
146
 
59
147
  If the first line begins with three colons, the text following
60
148
  the colons identifies the language (ruby in the example).
61
149
  The first line is removed from the code block before processing.
62
150
 
63
- Run the above example with:
64
-
65
- ruby simple.rb
66
-
67
151
  The directory *examples* contains ready to run, simple Sinatra app. Try
68
152
 
69
153
  rackup -p 4567 config.ru
@@ -83,51 +167,43 @@ and contemplate the sheer beauty of the rendered code.
83
167
  ## Supported Highlighters
84
168
 
85
169
  These currently include: *Syntax* (fast), *Coderay* (very fast),
86
- *Ultraviolet* (slow).
170
+ *Ultraviolet* (slow, but highlights almost any language).
87
171
 
88
- ### Syntax
172
+ The *Codehighlighter* gem provides a thin interface over a bunch of
173
+ exisitng code highlighters to make their usage as generic possible.
89
174
 
90
- Supported languages:
175
+ What does it mean? Explain.
91
176
 
92
- * xml
93
- * ruby
94
177
 
95
- I added support for these languages:
178
+ ### [Syntax](http://syntax.rubyforge.org/)
96
179
 
97
- * ansic
98
- * javascript
99
- * css21
100
- * sqlite
180
+ Languages supported by *Syntax*:
181
+
182
+ * xml
183
+ * ruby
101
184
 
102
185
 
103
186
  ### [Coderay](http://coderay.rubychan.de/)
104
187
 
105
- Supported languages:
106
-
107
- * C
108
- * CSS
109
- * Delphi
110
- * diff
111
- * HTML
112
- * RHTML (Rails)
113
- * Nitro-XHTML
114
- * Java
115
- * JavaScript
116
- * JSON
188
+ Languages supported by *Coderay*:
189
+
190
+ * C, CSS
191
+ * Delphi, diff
192
+ * HTML, RHTML (Rails), Nitro-XHTML
193
+ * Java, JavaScript, JSON
117
194
  * Ruby
118
195
  * YAML
119
196
 
120
197
  ### [Google Code Prettify](http://code.google.com/p/google-code-prettify/), pure Javascript
121
198
 
122
- Supported languages:
199
+ Languages supported by *Prettify*:
123
200
 
124
201
  * css, lisp, hs, lua, sql, vb, wiki,
125
202
  * bsh, c, cc, cpp, cs, csh, cyc, cv, htm, html,
126
203
  * java, js, m, mxml, perl, pl, pm, py, rb, sh,
127
204
  * xhtml, xml, xsl
128
205
 
129
-
130
- ### Ultraviolet
206
+ ### [Ultraviolet](http://ultraviolet.rubyforge.org/)
131
207
 
132
208
  The *ultraviolet* gem needs oniguruma regexp library.
133
209
 
@@ -142,165 +218,39 @@ Now, install the gem:
142
218
 
143
219
  sudo gem install ultraviolet
144
220
 
145
- [Ultraviolet themes gallery](: http://ultraviolet.rubyforge.org/themes.xhtml)
221
+ See also [Ultraviolet themes gallery](http://ultraviolet.rubyforge.org/themes.xhtml)
146
222
 
147
223
  Ultraviolet supports almost any language:
148
224
 
149
- * actionscript
150
- * active4d
151
- * active4d\_html
152
- * active4d\_ini
153
- * active4d\_library
154
- * ada
155
- * antlr
156
- * apache
157
- * applescript
158
- * asp
159
- * asp\_vb.net
160
- * bibtex
161
- * blog\_html
162
- * blog\_markdown
163
- * blog\_text
164
- * blog\_textile
165
- * build
166
- * bulletin\_board
167
- * c
168
- * c++
169
- * cake
170
- * camlp4
171
- * cm
172
- * coldfusion
173
- * context\_free
174
- * cs
175
- * css
176
- * css\_experimental
177
- * csv
178
- * d
179
- * diff
180
- * dokuwiki
181
- * dot
182
- * doxygen
183
- * dylan
184
- * eiffel
185
- * erlang
186
- * f-script
187
- * fortran
188
- * fxscript
189
- * greasemonkey
190
- * gri
191
- * groovy
192
- * gtd
193
- * gtdalt
194
- * haml
195
- * haskell
196
- * html
197
- * html-asp
198
- * html\_django
199
- * html\_for\_asp.net
200
- * html\_mason
201
- * html\_rails
202
- * html\_tcl
203
- * icalendar
204
- * inform
205
- * ini
206
- * installer\_distribution\_script
207
- * io
208
- * java
209
- * javaproperties
210
- * javascript
211
- * javascript\_+\_prototype
212
- * javascript\_+\_prototype\_bracketed
213
- * jquery\_javascript
214
- * json
215
- * languagedefinition
216
- * latex
217
- * latex\_beamer
218
- * latex\_log
219
- * latex\_memoir
220
- * lexflex
221
- * lighttpd
222
- * lilypond
223
- * lisp
224
- * literate\_haskell
225
- * logo
226
- * logtalk
227
- * lua
228
- * m
229
- * macports\_portfile
230
- * mail
231
- * makefile
232
- * man
233
- * markdown
234
- * mediawiki
235
- * mel
236
- * mips
237
- * mod\_perl
238
- * modula-3
239
- * moinmoin
240
- * mootools
241
- * movable\_type
242
- * multimarkdown
243
- * objective-c
244
- * objective-c++
245
- * ocaml
246
- * ocamllex
247
- * ocamlyacc
248
- * opengl
249
- * pascal
250
- * perl
251
- * php
252
- * plain\_text
253
- * pmwiki
254
- * postscript
255
- * processing
256
- * prolog
257
- * property\_list
258
- * python
259
- * python\_django
260
- * qmake\_project
261
- * qt\_c++
262
- * quake3\_config
263
- * r
264
- * r\_console
265
- * ragel
266
- * rd\_r\_documentation
267
- * regexp
268
- * regular\_expressions\_oniguruma
269
- * regular\_expressions\_python
270
- * release\_notes
271
- * remind
272
- * restructuredtext
273
- * rez
274
- * ruby
275
- * ruby\_experimental
276
- * ruby\_on\_rails
277
- * s5
278
- * scheme
279
- * scilab
280
- * setext
281
- * shell-unix-generic
282
- * slate
283
- * smarty
284
- * sql
285
- * sql\_rails
286
- * ssh-config
287
- * standard\_ml
288
- * strings\_file
289
- * subversion\_commit\_message
290
- * sweave
291
- * swig
292
- * tcl
293
- * template\_toolkit
294
- * tex
295
- * tex\_math
296
- * textile
297
- * tsv
298
- * twiki
299
- * txt2tags
225
+ * actionscript, active4d, active4d\_html, active4d\_ini, active4d\_library,
226
+ ada, antlr, apache, applescript, asp, asp\_vb.net
227
+ * bibtex, blog\_html, blog\_markdown, blog\_text, blog\_textile, build,
228
+ bulletin\_board
229
+ * c, c++, cake, camlp4, cm, coldusion, context\_free, cs, css, css\_experimental,
230
+ csv
231
+ * d, diff, dokuwiki, dot, doxygen, dylan
232
+ * eiffel, erlang, f-script, fortran, fxscript
233
+ * greasemonkey, gri, groovy, gtd, gtdalt
234
+ * haml, haskell, html, html-asp, html\_django, html\_for\_asp.net, html\_mason,
235
+ html\_rails, html\_tcl
236
+ * icalendar, inform, ini, installer\_distribution\_script, io
237
+ * java, javaproperties, javascript, javascript\_+\_prototype,
238
+ javascript\_+\_prototype\_bracketed, jquery\_javascript, json
239
+ * languagedefinition, latex, latex\_beamer, latex\_log, latex\_memoir, lexflex,
240
+ lighttpd, lilypond, lisp, literate\_haskell, logo, logtalk, lua
241
+ * m, macports\_portfile, mail, makefile, man, markdown, mediawiki, mel,
242
+ mips, mod\_perl, modula-3, moinmoin, mootools, movable\_type, multimarkdown
243
+ * objective-c, objective-c++, ocaml, ocamllex, ocamlyacc, opengl
244
+ * pascal, perl, php, plain\_text, pmwiki, postscript, processing,
245
+ prolog, property\_list, python, python\_django
246
+ * qmake\_project, qt\_c++, quake3\_config
247
+ * r, r\_console, ragel, rd\_r\_documentation, regexp,
248
+ regular\_expressions\_oniguruma, regular\_expressions\_python, release\_notes
249
+ remind, restructuredtext, rez, ruby, ruby\_experimental, ruby\_on\_rails
250
+ * s5, scheme, scilab, setext, shell-unix-generic, slate, smarty,
251
+ sql, sql\_rails, ssh-config, standard\_ml, strings\_file, subversion\_commit\_message,
252
+ sweave, swig
253
+ * tcl, template\_toolkit, tex, tex\_math, textile, tsv, twiki, txt2tags
300
254
  * vectorscript
301
- * xhtml\_1.0
302
- * xml
303
- * xml\_strict
304
- * xsl
305
- * yaml
306
- * yui\_javascript
255
+ * xhtml\_1.0, xml, xml\_strict, xsl
256
+ * yaml, yui\_javascript
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ require "rake"
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gemspec|
6
+ gemspec.name = "rack-codehighlighter"
7
+ gemspec.summary = "Rack Middleware for Code Highlighting."
8
+ gemspec.email = "matwb@univ.gda.pl"
9
+ gemspec.homepage = "http://github.com/wbzyl/rack-codehighlighter"
10
+ gemspec.authors = ["Wlodek Bzyl"]
11
+ gemspec.description = gemspec.summary
12
+
13
+ gemspec.files = %w[LICENSE TODO Rakefile VERSION.yml] + FileList['lib/**/*.rb', "examples/**/*"]
14
+
15
+ gemspec.add_runtime_dependency 'rack', '>=1.0.0'
16
+ gemspec.add_runtime_dependency 'hpricot', '>=0.8.1'
17
+
18
+ gemspec.add_development_dependency 'rack-test', '>=0.3.0'
19
+ end
20
+ rescue LoadError
21
+ puts "Jeweler not available."
22
+ puts "Install it with:"
23
+ puts " sudo gem install technicalpickles-jeweler -s http://gems.github.com"
24
+ end
25
+
26
+ #Rake::TestTask.new(:test) do |t|
27
+ # t.libs << 'lib' << 'test'
28
+ # t.pattern = 'test/**/*_test.rb'
29
+ # t.verbose = false
30
+ #end
data/TODO ADDED
@@ -0,0 +1,22 @@
1
+
2
+ [1.05.2009, done]
3
+ Add support for code-prettify:
4
+
5
+ * [source code](http://code.google.com/p/google-code-prettify/)
6
+ [example](http://google-code-prettify.googlecode.com/svn/trunk/README.html)
7
+
8
+
9
+ * see http://tomayko.com/writings/javascript-prettification
10
+ (support for jQuery, new pallette)
11
+
12
+ * example:
13
+ <pre class="prettyprint lang-html">
14
+ The lang-* class specifies the language file extensions.
15
+ File extensions supported by default include
16
+ "bsh", "c", "cc", "cpp", "cs", "csh", "cyc", "cv", "htm", "html",
17
+ "java", "js", "m", "mxml", "perl", "pl", "pm", "py", "rb", "sh",
18
+ "xhtml", "xml", "xsl".
19
+ </pre>
20
+
21
+ [1.05.2009]
22
+ Add support for unobtrustive Code Highlighter By Dan Webb 11/2005
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 5
3
+ :major: 0
4
+ :minor: 1
@@ -14,7 +14,9 @@ module Rack
14
14
  @app = app
15
15
  @highlighter = highlighter
16
16
 
17
- @opts = { :element => "//pre/code", :pattern => /\A:::(\w+)\s*\n/ }
17
+ @opts = { :element => "//pre/code",
18
+ :pattern => /\A:::(\w+)\s*\n/,
19
+ :reason => "[...ugly code removed...]" }
18
20
 
19
21
  @opts.merge! opts
20
22
  end
@@ -69,6 +71,10 @@ module Rack
69
71
  ]
70
72
  end
71
73
 
74
+ def censor(string)
75
+ "<pre>#{@opts[:reason]}</pre>"
76
+ end
77
+
72
78
  def syntax(string)
73
79
  translate = {
74
80
  'html' => 'xml',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wbzyl-rack-codehighlighter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wlodek Bzyl
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-31 00:00:00 -07:00
12
+ date: 2009-06-06 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,6 +52,10 @@ extra_rdoc_files:
52
52
  - LICENSE
53
53
  - README.markdown
54
54
  files:
55
+ - LICENSE
56
+ - Rakefile
57
+ - TODO
58
+ - VERSION.yml
55
59
  - examples/app.rb
56
60
  - examples/config.ru
57
61
  - examples/public/javascripts/lang-css.js
@@ -80,7 +84,6 @@ files:
80
84
  - examples/views/index.rdiscount
81
85
  - examples/views/layout.rdiscount
82
86
  - lib/rack/codehighlighter.rb
83
- - LICENSE
84
87
  - README.markdown
85
88
  has_rdoc: false
86
89
  homepage: http://github.com/wbzyl/rack-codehighlighter