downr 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -19,4 +19,4 @@ vendor
19
19
 
20
20
  # Sublime project files
21
21
  *.sublime-project
22
- *.sublime-workspace
22
+ *.sublime-workspace
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Downr::VERSION
9
9
  spec.authors = ["David Rivera"]
10
10
  spec.email = ["david.r.rivera193@gmail.com"]
11
- spec.summary = %q{Custom wrapper for RedCarpet}
11
+ spec.summary = %q{Rails friendly Github Falvored Markdown}
12
12
  spec.description = %q{Wrapper for RedCarpet, adding syntax highlighting, emojis etc.}
13
13
  spec.homepage = "https://github.com/davidrivera/Downr"
14
14
  spec.license = "MIT"
@@ -3,6 +3,7 @@
3
3
  if defined?(::Rails)
4
4
  require 'downr/action_view/helpers'
5
5
  require 'downr/railtie'
6
+ require 'downr/engine'
6
7
  end
7
8
 
8
9
  # Namespace for classes and modules that handle markdown parsing
@@ -10,12 +11,13 @@ module Downr
10
11
 
11
12
  autoload :Pygmentize, 'pygmentize'
12
13
  autoload :Redcarpet, 'redcarpet'
14
+ autoload :RailsEmoji, 'rails_emoji'
13
15
  autoload :Render, 'downr/render'
14
16
  autoload :Configuration, 'downr/configuration'
15
17
  autoload :Markdown, 'downr/markdown'
16
18
 
17
- # @attr [Configuration] configuration the configuration used for initializing the parser
18
- # @attr [Markdown] markdown the markdown object created from the configuration
19
+ # @attr Configuration configuration the configuration used for initializing the parser
20
+ # @attr Markdown markdown the markdown object created from the configuration
19
21
  class << self
20
22
  attr_accessor :configuration, :markdown
21
23
  end
@@ -0,0 +1,6 @@
1
+ module Downr
2
+ # Engine to patch through RailsEmoji assets
3
+ class Engine < ::Rails::Engine
4
+ require 'rails_emoji'
5
+ end
6
+ end
@@ -1,5 +1,3 @@
1
- require 'redcarpet'
2
-
3
1
  module Downr
4
2
 
5
3
  # This class is a wrapper for the
@@ -7,6 +5,7 @@ module Downr
7
5
  #
8
6
  # @attr [Redcarpet::Markdown] renderer
9
7
  class Markdown
8
+ # static renderer
10
9
  @@renderer
11
10
 
12
11
  attr_accessor :renderer
@@ -1,12 +1,11 @@
1
1
  module Downr
2
2
 
3
- ##
4
3
  # Lets us tie up a Rails view helper
5
- class Railtie < ::Rails::Railtie
4
+ class Railtie < ::Rails::Railtie
6
5
  initializer "downr.configure_view_controller" do |app|
7
6
  ActiveSupport.on_load :action_view do
8
7
  ActionView::Base.send :include, Helpers
9
8
  end
10
9
  end
11
- end
10
+ end
12
11
  end
@@ -1,8 +1,14 @@
1
1
  module Downr
2
+
2
3
  # This class wraps both pygmentize and
3
4
  # RailsEmoji gems to create a custom renderer
4
5
  class Render < Redcarpet::Render::HTML
5
6
 
7
+ # will override the postprocess method to
8
+ # perform SmartyPants replacements once
9
+ # the rendering is complete.
10
+ include Redcarpet::Render::SmartyPants
11
+
6
12
  # Initializes the Render object
7
13
  #
8
14
  # @option opts [Boolean] :pygmentize Code colors
@@ -13,6 +19,9 @@ module Downr
13
19
  super
14
20
  end
15
21
 
22
+
23
+ # Block-level calls
24
+
16
25
  # Hook for Redcarpet render
17
26
  #
18
27
  # @param [String] code the code snippet to parse
@@ -21,23 +30,25 @@ module Downr
21
30
  # @return [String] html
22
31
  def block_code(code, language)
23
32
  if(@options[:pygmentize])
24
- pygmentize(code, language)
25
- else
26
- return code
33
+ return pygmentize(code, language)
27
34
  end
35
+
36
+ code
28
37
  end
29
38
 
39
+ # Pre/post-process
40
+
30
41
  # Hook for Redcarpet render
31
42
  #
32
- # @param [String] text the p block
43
+ # @param [String] full_document the complete doc
33
44
  #
34
45
  # @return [String] html
35
- def paragraph(text)
46
+ def postprocess(full_document)
36
47
  if(@options[:emojify])
37
- return emojify(text)
38
- else
39
- return text
48
+ return emojify(full_document)
40
49
  end
50
+
51
+ full_document
41
52
  end
42
53
 
43
54
  private
@@ -77,7 +88,7 @@ module Downr
77
88
  def emojify(content)
78
89
  content.to_str.gsub(/:([a-z0-9\+\-_]+):/) do |match|
79
90
  RailsEmoji.render match, size: '20x20'
80
- end.html_safe if content.present?
91
+ end
81
92
  end
82
93
 
83
94
  #Uses Pygmentize to color code
@@ -1,3 +1,4 @@
1
+ # Gem Version
1
2
  module Downr
2
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
3
4
  end
@@ -1,3 +1,8 @@
1
+ # Downr configuration
2
+ #
3
+ # @yield configuration for Downr
4
+ # @yieldparam config
5
+ # @yieldreturn config
1
6
  Downr.configure do |config|
2
7
  config.options = {
3
8
 
@@ -5,5 +5,5 @@ describe Downr::Render do
5
5
  Downr::Render.any_instance.stub(:initialize).and_return(Downr::Render.new({}))
6
6
  end
7
7
  it{ should respond_to(:block_code) }
8
- it{ should respond_to(:paragraph) }
8
+ it{ should respond_to(:postprocess) }
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: downr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-15 00:00:00.000000000 Z
12
+ date: 2014-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -158,6 +158,7 @@ files:
158
158
  - lib/downr.rb
159
159
  - lib/downr/action_view/helpers.rb
160
160
  - lib/downr/configuration.rb
161
+ - lib/downr/engine.rb
161
162
  - lib/downr/markdown.rb
162
163
  - lib/downr/railtie.rb
163
164
  - lib/downr/render.rb
@@ -195,7 +196,7 @@ rubyforge_project:
195
196
  rubygems_version: 1.8.23
196
197
  signing_key:
197
198
  specification_version: 3
198
- summary: Custom wrapper for RedCarpet
199
+ summary: Rails friendly Github Falvored Markdown
199
200
  test_files:
200
201
  - spec/lib/downr/action_view/helpers_spec.rb
201
202
  - spec/lib/downr/configuration_spec.rb