gmd 1.2.1 → 1.3.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/bin/gmd CHANGED
@@ -52,21 +52,11 @@ layout = Gmd::default_layout unless layout
52
52
 
53
53
  output_file = file.gsub(/\.(md|markdown)\z/, '') + '.html' unless output_file
54
54
 
55
- Gmd::locals[:options] = options
56
-
57
- # output = Tilt.new(file).render(self, locals)
58
- # Use redcarpet here directly
59
- output = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
60
- :no_intra_emphasis => true,
61
- :tables => true,
62
- :fenced_code_blocks => true,
63
- :autolink => true,
64
- :strikethrough => true,
65
- :lax_html_blocks => true,
66
- :space_after_headers => true,
67
- :superscript => false
68
- ).render(File.read(file))
69
-
70
- output = Tilt.new(layout).render(self, Gmd::locals) { output } if layout
55
+ Gmd::var[:options] = options
56
+
57
+ Tilt.prefer Tilt::RedcarpetTemplate
58
+
59
+ output = Gmd::tilt_render(file)
60
+ output = Gmd::tilt_render(layout){ output } if layout
71
61
 
72
62
  File.open(output_file, "wb") { |f| f.write(output) }
@@ -0,0 +1,11 @@
1
+ require "date"
2
+
3
+ module Gmd
4
+ module Helpers
5
+
6
+ def date_and_time(format = "%d.%m.%Y %H:%M")
7
+ DateTime.now.strftime(format)
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require "redcarpet"
2
+
3
+ # Fix for redcarpet
4
+ class Tilt::RedcarpetTemplate
5
+
6
+ def prepare
7
+ klass = [Redcarpet2, Redcarpet1].detect { |e| e.engine_initialized? }
8
+ @engine = klass.new(file, line, options) { data }
9
+ end
10
+
11
+ end
@@ -14,7 +14,7 @@ $(document).ready(function() {
14
14
  </script>
15
15
 
16
16
  <%# MathJax %>
17
- <% if locals[:options][:use_tex] %>
17
+ <% if var[:options][:use_tex] %>
18
18
  <script type="text/x-mathjax-config">
19
19
  MathJax.Hub.Config({
20
20
  jax: ["input/TeX","output/HTML-CSS"],
@@ -1,8 +1,8 @@
1
1
  <html>
2
2
  <head>
3
3
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4
- <%= Gmd.layout_meta_tags %>
5
- <%= Gmd.load_common(:header) %>
4
+ <%= layout_meta_tags %>
5
+ <%= load_common(:header) %>
6
6
  <style>
7
7
  /*
8
8
  Some simple Github-like styles.
@@ -1,8 +1,8 @@
1
1
  <html>
2
2
  <head>
3
3
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4
- <%= Gmd.layout_meta_tags %>
5
- <%= Gmd.load_common(:header) %>
4
+ <%= layout_meta_tags %>
5
+ <%= load_common(:header) %>
6
6
  <style>
7
7
  <%= File.read(File.dirname(__FILE__) + "/style.css") %>
8
8
  </style>
@@ -1,8 +1,8 @@
1
1
  <html>
2
2
  <head>
3
3
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4
- <%= Gmd.layout_meta_tags %>
5
- <%= Gmd.load_common(:header) %>
4
+ <%= layout_meta_tags %>
5
+ <%= load_common(:header) %>
6
6
  <style>
7
7
  body {background-color:#f8f8f8;font-family:Helvetica;}
8
8
  h1,h2,h3,h4,h5,h6{border:0;}
data/lib/gmd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gmd
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/gmd.rb CHANGED
@@ -2,6 +2,8 @@ require "gmd/version"
2
2
  require "tilt"
3
3
  require "redcarpet"
4
4
  require "erb"
5
+ require "gmd/helpers"
6
+ require "gmd/redcarpet_template_fix"
5
7
 
6
8
  module Gmd
7
9
  class << self
@@ -54,15 +56,18 @@ module Gmd
54
56
  ]
55
57
  filepath = choose_file_from_paths(paths)
56
58
  raise "Unable to find file: #{file}" unless filepath
57
- Tilt.new(filepath).render(self, locals).force_encoding("UTF-8")
59
+ tilt_render(filepath)
58
60
  end
59
61
 
62
+ # Escapes all markdown symbols found
60
63
  def escape_markdown(str)
61
64
  symbols = "\\`*_{}[]()#+-.!".split('')
62
65
  symbols.each { |s| str.gsub!(s, "\\" + s) }
63
66
  str
64
67
  end
65
68
 
69
+ # Used to find and autoescape LaTeX in Markdown files
70
+ # NOT SAFE YET! DO NO USE THIS!
66
71
  def fix_latex(str)
67
72
  inline_exp = /(([^\$]\${1}[^\$].*?[^\$]?\${1}[^\$]))/
68
73
  multline_exp = /((\\begin\{(\w+?)\}.+?\\end\{\3\})|(\$\$.+?\$\$))/m
@@ -71,9 +76,52 @@ module Gmd
71
76
  str
72
77
  end
73
78
 
74
- def locals
75
- @locals ||= {}
79
+ def var
80
+ @var ||= {}
76
81
  end
77
-
82
+
83
+ # Here we can specify the default options for different renderers
84
+ def rendering_options(engine)
85
+ case engine.name
86
+ when /Redcarpet/
87
+ {
88
+ :no_intra_emphasis => true,
89
+ :tables => true,
90
+ :fenced_code_blocks => true,
91
+ :autolink => true,
92
+ :strikethrough => true,
93
+ :lax_html_blocks => true,
94
+ :space_after_headers => true,
95
+ :superscript => false
96
+ }
97
+ end
98
+ end
99
+
100
+ def tilt_render(file, locals = {}, &block)
101
+ Tilt.new(file, 1, rendering_options(Tilt[file]) || {})
102
+ .render(Gmd::ExtraBinding, locals, &block)
103
+ .force_encoding("UTF-8")
104
+ end
105
+
78
106
  end
107
+
108
+ class ExtraBinding
109
+ class << self
110
+
111
+ include Helpers
112
+
113
+ def method_missing(method_sym, *arguments, &block)
114
+ if Gmd.respond_to?(method_sym)
115
+ Gmd.__send__(method_sym, *arguments, &block)
116
+ else
117
+ super
118
+ end
119
+ end
120
+
121
+ def respond_to?(method_sym)
122
+ super || Gmd.respond_to?(method_sym)
123
+ end
124
+ end
125
+ end
126
+
79
127
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redcarpet
16
- requirement: &30064788 !ruby/object:Gem::Requirement
16
+ requirement: &30605592 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *30064788
24
+ version_requirements: *30605592
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tilt
27
- requirement: &30101388 !ruby/object:Gem::Requirement
27
+ requirement: &30605340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *30101388
35
+ version_requirements: *30605340
36
36
  description: gmd is a small command-line utility to easily generate fancy HTML from
37
37
  Markdown.
38
38
  email:
@@ -49,6 +49,8 @@ files:
49
49
  - bin/gmd
50
50
  - gmd.gemspec
51
51
  - lib/gmd.rb
52
+ - lib/gmd/helpers.rb
53
+ - lib/gmd/redcarpet_template_fix.rb
52
54
  - lib/gmd/templates/common/header.html.erb
53
55
  - lib/gmd/templates/common/highlight_js/github.css
54
56
  - lib/gmd/templates/common/highlight_js/highlight.pack.js