any2html 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ require 'any2html'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "any2html"
8
- s.version = '0.0.3'
8
+ s.version = '0.0.4'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.required_ruby_version = '>= 1.9.0'
11
11
 
@@ -3,8 +3,8 @@ require 'bluecloth'
3
3
  require 'RedCloth'
4
4
  require 'sinatra'
5
5
  require 'haml'
6
-
7
-
6
+ require 'textile_extensions'
7
+ RedCloth.send(:include, RailsGuides::TextileExtensions)
8
8
 
9
9
  class Any2html < Sinatra::Application
10
10
  map1 = {
@@ -0,0 +1,63 @@
1
+ require 'active_support/core_ext/object/inclusion'
2
+
3
+ module RailsGuides
4
+ module TextileExtensions
5
+ def notestuff(body)
6
+ # The following regexp detects special labels followed by a
7
+ # paragraph, perhaps at the end of the document.
8
+ #
9
+ # It is important that we do not eat more than one newline
10
+ # because formatting may be wrong otherwise. For example,
11
+ # if a bulleted list follows the first item is not rendered
12
+ # as a list item, but as a paragraph starting with a plain
13
+ # asterisk.
14
+ body.gsub!(/^(TIP|IMPORTANT|CAUTION|WARNING|NOTE|INFO)[.:](.*?)(\n(?=\n)|\Z)/m) do |m|
15
+ css_class = case $1
16
+ when 'CAUTION', 'IMPORTANT'
17
+ 'warning'
18
+ when 'TIP'
19
+ 'info'
20
+ else
21
+ $1.downcase
22
+ end
23
+ %Q(<div class="#{css_class}"><p>#{$2.strip}</p></div>)
24
+ end
25
+ end
26
+
27
+ def plusplus(body)
28
+ body.gsub!(/\+(.*?)\+/) do |m|
29
+ "<notextile><tt>#{$1}</tt></notextile>"
30
+ end
31
+
32
+ # The real plus sign
33
+ body.gsub!('<plus>', '+')
34
+ end
35
+
36
+ def brush_for(code_type)
37
+ case code_type
38
+ when 'ruby', 'sql', 'plain'
39
+ code_type
40
+ when 'erb'
41
+ 'ruby; html-script: true'
42
+ when 'html'
43
+ 'xml' # html is understood, but there are .xml rules in the CSS
44
+ else
45
+ 'plain'
46
+ end
47
+ end
48
+
49
+ def code(body)
50
+ body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)</\1>}m) do |m|
51
+ <<HTML
52
+ <notextile>
53
+ <div class="code_container">
54
+ <pre class="brush: #{brush_for($1)}; gutter: false; toolbar: false">
55
+ #{ERB::Util.h($2).strip}
56
+ </pre>
57
+ </div>
58
+ </notextile>
59
+ HTML
60
+ end
61
+ end
62
+ end
63
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: any2html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -73,6 +73,7 @@ files:
73
73
  - any2html.gemspec
74
74
  - bin/any2html
75
75
  - lib/any2html.rb
76
+ - lib/textile_extensions.rb
76
77
  homepage: http://github.com/danchoi/any2html
77
78
  licenses: []
78
79
  post_install_message: