markdown_cache 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ef95340deb2d6fa01cefd8d0bb11bef0e100799
4
+ data.tar.gz: 1fcb751a15adc1af7058f38a155da72b49e59b1b
5
+ SHA512:
6
+ metadata.gz: 3422cbc4e65f8642527d6631a70da2023cc6f64393e8a86c6741cf54af3d93b7f6b2c41d9641055007ab2647f3a59354d5d1e3726809ccaa1b3e41e732cb134a
7
+ data.tar.gz: c107bb254c747e12ab7ac40745d48a0e98267aff107d36c3da3990258f07abec4ce447ae60d6ba16f6f43e80e6861b563da84b4d1216e696ab1a9e173da416dc
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ services:
5
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in markdown_cache.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Sebastien Saunier
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ [![Build Status](https://travis-ci.org/ssaunier/markdown_cache.svg?branch=master)](https://travis-ci.org/ssaunier/markdown_cache)
2
+
3
+ ## MarkdownCache
4
+
5
+ Simple and zero-configuration gem to quickly add Markdown rendering to your Rails views. Once installed, just use in any view:
6
+
7
+ ```erb
8
+ <%= markdown "**Hello** _world_" %>
9
+ ```
10
+
11
+ ### Dependencies & Defaults
12
+
13
+ This gem uses `kramdown` and `rouge` and will require them automatically. **You also need a Redis server running** both locally and in production as this gem uses a redis-back cached.
14
+
15
+ The selected input format is **GitHub Flafored Markdown**.
16
+
17
+ ### Setup
18
+
19
+ Add this to your `Gemfile`, then run `bundle install` :
20
+
21
+ ```ruby
22
+ gem "markdown_cache", "~> 0.1"
23
+ ```
24
+
25
+ You may use the provided CSS file for syntax highlighting (GitHub style) or download any pygments-compatible CSS stylesheet (`.highlight` CSS class):
26
+
27
+ ```css
28
+ /*
29
+ *= require markdown_cache
30
+ */
31
+ ```
32
+
33
+ By default, the gem will pick up the local Redis instance or the one defined with `REDIS_URL` but if you need to be specific, add an initializer to your Rails app, for instance:
34
+
35
+ ```ruby
36
+ # config/initializers/markdown_cache.rb
37
+ if Rails.env.production?
38
+ MarkdownCache.configure do |config|
39
+ config.redis = { url: ENV['REDISCLOUD_URL'] }
40
+ end
41
+ end
42
+ ```
43
+
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.warning = false
8
+ t.test_files = FileList['test/**/*_test.rb']
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "markdown_cache"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require "markdown_cache/version"
2
+ require "markdown_cache/configuration"
3
+ require "markdown_cache/renderer"
4
+
5
+ if defined?(Rails::Railtie)
6
+ require "markdown_cache/railtie"
7
+ require "markdown_cache/rails/engine" # For the assets
8
+ end
@@ -0,0 +1,21 @@
1
+ require "redis"
2
+
3
+ module MarkdownCache
4
+ def self.configuration
5
+ @configuration ||= Configuration.new
6
+ end
7
+
8
+ def self.configure
9
+ yield(configuration) if block_given?
10
+ end
11
+
12
+ class Configuration
13
+ def redis=(options)
14
+ @redis = Redis.new(options)
15
+ end
16
+
17
+ def redis
18
+ @redis ||= Redis.new
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,8 @@
1
+ module MarkdownCache
2
+ module Helper
3
+ def markdown(text)
4
+ renderer = Renderer.new
5
+ renderer.render(text).html_safe
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ module MarkdownCache
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ require 'markdown_cache/helper'
2
+
3
+ module MarkdownCache
4
+ class Railtie < Rails::Railtie
5
+ initializer "markdown_cache.helper" do
6
+ ActionView::Base.send :include, Helper
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,47 @@
1
+ require 'kramdown'
2
+ require 'digest/sha1'
3
+
4
+ module MarkdownCache
5
+ class Renderer
6
+ EXPIRE = 7 * 24 * 3600 # 7 days
7
+
8
+ def render(text)
9
+ return "" if text.nil?
10
+ from_cache(key(Digest::SHA1.hexdigest(text))) do
11
+ kramdown_render(text)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def kramdown_render(text)
18
+ Kramdown::Document.new(text, kramdown_options).to_html
19
+ end
20
+
21
+ def kramdown_options
22
+ {
23
+ input: 'GFM',
24
+ syntax_highlighter: 'rouge'
25
+ }
26
+ end
27
+
28
+ def from_cache(key, &block)
29
+ if (value = redis.get(key)).nil?
30
+ value = yield(self)
31
+ redis.set(key, Marshal.dump(value))
32
+ redis.expire(key, EXPIRE)
33
+ value
34
+ else
35
+ Marshal.load(value)
36
+ end
37
+ end
38
+
39
+ def key(sha)
40
+ "markdown:#{sha}"
41
+ end
42
+
43
+ def redis
44
+ MarkdownCache.configuration.redis
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module MarkdownCache
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'markdown_cache/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "markdown_cache"
8
+ spec.version = MarkdownCache::VERSION
9
+ spec.authors = ["Sebastien Saunier"]
10
+ spec.email = ["seb@saunier.me"]
11
+
12
+ spec.summary = %q{Markdown (GFM) view helper with redis-backed cache}
13
+ spec.homepage = "https://github.com/ssaunier/markdown_cache"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "redis", ">= 3.0"
22
+ spec.add_dependency "kramdown", ">= 1.0"
23
+ spec.add_dependency "rouge", ">= 1.0"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.11"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+ spec.add_development_dependency "minitest-reporters", "~> 1.1"
29
+ end
@@ -0,0 +1,211 @@
1
+ /* $ rougify style github */
2
+
3
+ .highlight table td { padding: 5px; }
4
+ .highlight table pre { margin: 0; }
5
+ .highlight .cm {
6
+ color: #999988;
7
+ font-style: italic;
8
+ }
9
+ .highlight .cp {
10
+ color: #999999;
11
+ font-weight: bold;
12
+ }
13
+ .highlight .c1 {
14
+ color: #999988;
15
+ font-style: italic;
16
+ }
17
+ .highlight .cs {
18
+ color: #999999;
19
+ font-weight: bold;
20
+ font-style: italic;
21
+ }
22
+ .highlight .c, .highlight .cd {
23
+ color: #999988;
24
+ font-style: italic;
25
+ }
26
+ .highlight .err {
27
+ color: #a61717;
28
+ background-color: #e3d2d2;
29
+ }
30
+ .highlight .gd {
31
+ color: #000000;
32
+ background-color: #ffdddd;
33
+ }
34
+ .highlight .ge {
35
+ color: #000000;
36
+ font-style: italic;
37
+ }
38
+ .highlight .gr {
39
+ color: #aa0000;
40
+ }
41
+ .highlight .gh {
42
+ color: #999999;
43
+ }
44
+ .highlight .gi {
45
+ color: #000000;
46
+ background-color: #ddffdd;
47
+ }
48
+ .highlight .go {
49
+ color: #888888;
50
+ }
51
+ .highlight .gp {
52
+ color: #555555;
53
+ }
54
+ .highlight .gs {
55
+ font-weight: bold;
56
+ }
57
+ .highlight .gu {
58
+ color: #aaaaaa;
59
+ }
60
+ .highlight .gt {
61
+ color: #aa0000;
62
+ }
63
+ .highlight .kc {
64
+ color: #000000;
65
+ font-weight: bold;
66
+ }
67
+ .highlight .kd {
68
+ color: #000000;
69
+ font-weight: bold;
70
+ }
71
+ .highlight .kn {
72
+ color: #000000;
73
+ font-weight: bold;
74
+ }
75
+ .highlight .kp {
76
+ color: #000000;
77
+ font-weight: bold;
78
+ }
79
+ .highlight .kr {
80
+ color: #000000;
81
+ font-weight: bold;
82
+ }
83
+ .highlight .kt {
84
+ color: #445588;
85
+ font-weight: bold;
86
+ }
87
+ .highlight .k, .highlight .kv {
88
+ color: #000000;
89
+ font-weight: bold;
90
+ }
91
+ .highlight .mf {
92
+ color: #009999;
93
+ }
94
+ .highlight .mh {
95
+ color: #009999;
96
+ }
97
+ .highlight .il {
98
+ color: #009999;
99
+ }
100
+ .highlight .mi {
101
+ color: #009999;
102
+ }
103
+ .highlight .mo {
104
+ color: #009999;
105
+ }
106
+ .highlight .m, .highlight .mb, .highlight .mx {
107
+ color: #009999;
108
+ }
109
+ .highlight .sb {
110
+ color: #d14;
111
+ }
112
+ .highlight .sc {
113
+ color: #d14;
114
+ }
115
+ .highlight .sd {
116
+ color: #d14;
117
+ }
118
+ .highlight .s2 {
119
+ color: #d14;
120
+ }
121
+ .highlight .se {
122
+ color: #d14;
123
+ }
124
+ .highlight .sh {
125
+ color: #d14;
126
+ }
127
+ .highlight .si {
128
+ color: #d14;
129
+ }
130
+ .highlight .sx {
131
+ color: #d14;
132
+ }
133
+ .highlight .sr {
134
+ color: #009926;
135
+ }
136
+ .highlight .s1 {
137
+ color: #d14;
138
+ }
139
+ .highlight .ss {
140
+ color: #990073;
141
+ }
142
+ .highlight .s {
143
+ color: #d14;
144
+ }
145
+ .highlight .na {
146
+ color: #008080;
147
+ }
148
+ .highlight .bp {
149
+ color: #999999;
150
+ }
151
+ .highlight .nb {
152
+ color: #0086B3;
153
+ }
154
+ .highlight .nc {
155
+ color: #445588;
156
+ font-weight: bold;
157
+ }
158
+ .highlight .no {
159
+ color: #008080;
160
+ }
161
+ .highlight .nd {
162
+ color: #3c5d5d;
163
+ font-weight: bold;
164
+ }
165
+ .highlight .ni {
166
+ color: #800080;
167
+ }
168
+ .highlight .ne {
169
+ color: #990000;
170
+ font-weight: bold;
171
+ }
172
+ .highlight .nf {
173
+ color: #990000;
174
+ font-weight: bold;
175
+ }
176
+ .highlight .nl {
177
+ color: #990000;
178
+ font-weight: bold;
179
+ }
180
+ .highlight .nn {
181
+ color: #555555;
182
+ }
183
+ .highlight .nt {
184
+ color: #000080;
185
+ }
186
+ .highlight .vc {
187
+ color: #008080;
188
+ }
189
+ .highlight .vg {
190
+ color: #008080;
191
+ }
192
+ .highlight .vi {
193
+ color: #008080;
194
+ }
195
+ .highlight .nv {
196
+ color: #008080;
197
+ }
198
+ .highlight .ow {
199
+ color: #000000;
200
+ font-weight: bold;
201
+ }
202
+ .highlight .o {
203
+ color: #000000;
204
+ font-weight: bold;
205
+ }
206
+ .highlight .w {
207
+ color: #bbbbbb;
208
+ }
209
+ .highlight {
210
+ background-color: #f8f8f8;
211
+ }
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdown_cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastien Saunier
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: kramdown
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rouge
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '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: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest-reporters
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.1'
111
+ description:
112
+ email:
113
+ - seb@saunier.me
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/console
125
+ - bin/setup
126
+ - lib/markdown_cache.rb
127
+ - lib/markdown_cache/configuration.rb
128
+ - lib/markdown_cache/helper.rb
129
+ - lib/markdown_cache/rails/engine.rb
130
+ - lib/markdown_cache/railtie.rb
131
+ - lib/markdown_cache/renderer.rb
132
+ - lib/markdown_cache/version.rb
133
+ - markdown_cache.gemspec
134
+ - vendor/assets/stylesheets/markdown_cache.css
135
+ homepage: https://github.com/ssaunier/markdown_cache
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.5.1
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Markdown (GFM) view helper with redis-backed cache
159
+ test_files: []