downr 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84ecbe56fb9a1150235d7408839f8c71799f8e16
4
+ data.tar.gz: 403894201e86c3273e06aecc1d48275b47c80096
5
+ SHA512:
6
+ metadata.gz: 16bdf37263ea1cd280ac5125a2c8adf591c0b484fe0d1aee6f5beb709f2937c58b44f92d00a0f2925114e808c311000d3b5332da07408fbc8afee4dcbce742c5
7
+ data.tar.gz: c3610136e9c286b1b09f9d46fa97b6acddd7232167992045881b7f6e8a7fd2679e2644ba864c17650a4c337e533261eaaaf1acb8fc78afec63ffdf914cb3ba2a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+ - ruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 David Rivera
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Downr [![Build Status](https://travis-ci.org/davidrivera/Downr.svg?branch=master)](https://travis-ci.org/davidrivera/Downr)
2
+ Simple Rails gem wrapper for RedCarpet, Pygmentize, and Emoji giving you a fun cool markdown renderer with all the fixin's
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'downr'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install downr
17
+
18
+ after run
19
+
20
+ $ rails g downr:install
21
+
22
+ this will create an initializer in
23
+
24
+ config/initializer/downr.rb
25
+
26
+ ## Usage
27
+
28
+ Crack open the initializer `config/initializers/downr.rb` and add/change any configuration options for the markdown rendering process. These options are passed straight to RedCarpet so you can head over there to check out all of the possible options.
29
+
30
+ ### View Helpers
31
+
32
+ `render_markdown "# Hello World"`
33
+
34
+ ### Or use directly
35
+
36
+ `Downr::Markdown.render("# Hello World")`
37
+
38
+ ## Tests
39
+
40
+ Just fork and run `rake`
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( http://github.com/davidrivera/downr/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
49
+
50
+ ## License
51
+
52
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'lib/downr'
7
+ t.test_files = FileList['test/lib/downr/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
data/downr.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'downr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "downr"
8
+ spec.version = Downr::VERSION
9
+ spec.authors = ["David Rivera"]
10
+ spec.email = ["david.r.rivera193@gmail.com"]
11
+ spec.summary = %q{Custom wrapper for RedCarpet}
12
+ spec.description = %q{Wrapper for RedCarpet, adding syntax highlighting, emojis etc.}
13
+ spec.homepage = "https://github.com/davidrivera/Downr"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency 'rails', '>= 3.1.0'
25
+ spec.add_dependency "rails_emoji", "~> 1.7.1"
26
+ spec.add_dependency "pygmentize", "~>0.0.3"
27
+ spec.add_dependency "redcarpet", "~>3.1.1"
28
+ end
data/lib/downr.rb ADDED
@@ -0,0 +1,24 @@
1
+ require "downr/version"
2
+ require 'downr/render'
3
+ require 'downr/configuration'
4
+ require 'downr/markdown'
5
+
6
+ if defined?(::Rails)
7
+ require 'downr/action_view/helpers'
8
+ require 'downr/railtie'
9
+ end
10
+
11
+ module Downr
12
+ # Your code goes here...
13
+ class << self
14
+ attr_accessor :configuration, :markdown
15
+ end
16
+
17
+ def self.configure
18
+ self.configuration ||= Configuration.new
19
+ yield(configuration)
20
+
21
+ self.markdown ||= Markdown.new
22
+ end
23
+
24
+ end
@@ -0,0 +1,7 @@
1
+ module Downr
2
+ module Helpers
3
+ def render_markdown(html)
4
+ Downr::Markdown.render(html).html_safe
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module Downr
2
+
3
+ class Configuration
4
+ @@options
5
+
6
+ attr_accessor :options
7
+
8
+ def initialize
9
+ @@options = {}
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ require 'redcarpet'
2
+
3
+ module Downr
4
+
5
+ class Markdown
6
+ @@renderer
7
+
8
+ attr_accessor :renderer
9
+
10
+ def initialize
11
+ options = Downr.configuration.options
12
+ render = Render.new
13
+
14
+ @@renderer = Redcarpet::Markdown.new(render, options)
15
+ end
16
+ def self.render text
17
+ @@renderer.render(text)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ module Downr
2
+ class Railtie < ::Rails::Railtie
3
+ initializer "downr.configure_view_controller" do |app|
4
+ ActiveSupport.on_load :action_view do
5
+ ActionView::Base.send :include, Helpers
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ require 'pygmentize'
2
+ require 'redcarpet'
3
+
4
+ module Downr
5
+ # This class wraps both pygmentize and
6
+ # RailsEmoji gems to create a custom renderer
7
+ class Render < Redcarpet::Render::HTML
8
+ def block_code(code, language)
9
+ pygmentiz(code, language)
10
+ end
11
+
12
+ def paragraph(text)
13
+ emojify(text)
14
+ end
15
+
16
+ private
17
+ def emojify(content)
18
+ content.to_str.gsub(/:([a-z0-9\+\-_]+):/) do |match|
19
+ RailsEmoji.render match, size: '20x20'
20
+ end.html_safe if content.present?
21
+ end
22
+ def pygmentiz(code, language)
23
+ language = language.nil? ? :sh : language
24
+ Pygmentize.process(code, language)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Downr
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,9 @@
1
+ module Downr
2
+ class InstallGenerator < Rails::Generators::NameBase
3
+ source_root File.expand_path('../../../templates', __FILE__)
4
+
5
+ def copy_files
6
+ copy_file 'downr.rb', 'config/initializers/downr.rb'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ Downr.configure do |config|
2
+ config.options = {
3
+ no_intra_emphasis: true,
4
+
5
+ fenced_code_blocks: true,
6
+ autolink: true,
7
+ disable_indented_code_blocks: false,
8
+ strikethrough: true,
9
+
10
+ space_after_headers: true,
11
+ superscript: true,
12
+ underline: true,
13
+ highlight: true,
14
+
15
+ filter_html: false, #do not allow any user-inputted HTML in the output.
16
+ no_images: false,
17
+ no_links: false,
18
+ no_styles: true,
19
+ safe_links_only: false,
20
+ with_toc_data: true,
21
+ hard_wrap: false,
22
+ xhtml: false,
23
+ prettify: true
24
+ }
25
+ end
@@ -0,0 +1,11 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Downr::Configuration do
4
+ subject { Downr::Configuration }
5
+
6
+ describe "configuration" do
7
+ it "must have options" do
8
+ Downr.configuration.options.wont_be_nil
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Downr::Markdown do
4
+ subject { Downr::Markdown }
5
+
6
+ describe "Object itself" do
7
+ it "must be initialized" do
8
+ a = Downr::Markdown.new
9
+ a.wont_be_nil
10
+ end
11
+ end
12
+
13
+ describe "render" do
14
+
15
+ it "must have a render" do
16
+ subject.must_respond_to(:render)
17
+ end
18
+
19
+ it "must render markdown" do
20
+ a = Downr::Markdown.render("# hello")
21
+ assert_equal "<h1>hello</h1>\n", a
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Downr::Render do
4
+ subject { Downr::Render }
5
+
6
+ describe "functions" do
7
+ before do
8
+ @a = Downr::Render.new
9
+ end
10
+
11
+ it "must have block_code" do
12
+ @a.must_respond_to(:block_code)
13
+ end
14
+
15
+ it "must have paragrah" do
16
+ @a.must_respond_to(:paragraph)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Downr do
4
+
5
+ it "must be defined" do
6
+ Downr::VERSION.wont_be_nil
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require File.expand_path('../../lib/downr.rb', __FILE__)
4
+ require File.expand_path('../../lib/generators/templates/downr',__FILE__)
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: downr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - David Rivera
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails_emoji
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.7.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.7.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: pygmentize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.3
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: redcarpet
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 3.1.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 3.1.1
97
+ description: Wrapper for RedCarpet, adding syntax highlighting, emojis etc.
98
+ email:
99
+ - david.r.rivera193@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .travis.yml
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - downr.gemspec
111
+ - lib/downr.rb
112
+ - lib/downr/action_view/helpers.rb
113
+ - lib/downr/configuration.rb
114
+ - lib/downr/markdown.rb
115
+ - lib/downr/railtie.rb
116
+ - lib/downr/render.rb
117
+ - lib/downr/version.rb
118
+ - lib/generators/downr/install/install_generator.rb
119
+ - lib/generators/templates/downr.rb
120
+ - test/lib/downr/configuration_test.rb
121
+ - test/lib/downr/markdown_test.rb
122
+ - test/lib/downr/render_test.rb
123
+ - test/lib/downr/version_test.rb
124
+ - test/test_helper.rb
125
+ homepage: https://github.com/davidrivera/Downr
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.0.3
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Custom wrapper for RedCarpet
149
+ test_files:
150
+ - test/lib/downr/configuration_test.rb
151
+ - test/lib/downr/markdown_test.rb
152
+ - test/lib/downr/render_test.rb
153
+ - test/lib/downr/version_test.rb
154
+ - test/test_helper.rb