markdown_views 0.4.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cf1dc33fd63dcb76e12249d77dd4759bd68060bf
4
+ data.tar.gz: 363c136ece7c0080001fb4f590bb01e70675064f
5
+ SHA512:
6
+ metadata.gz: 6da7e5a2607fa43d2c177a78988f7cf811bc9a41b6494b9db4689676d19a5932d50a4b916a72ac4156514729c99b9d141f70a63f04a62c00d4e566a393595dab
7
+ data.tar.gz: 34a616a2c482cdabfcce8e0a9b7123ad4770111ef48056d205609214c1d45c5bd2f2d5ee9dcbe714da51af64a140134a29d08e64063b318296569d4947c0c2f7
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .ruby-*
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in markdown_views.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014-2017 thomas morgan
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,60 @@
1
+ # MarkdownViews
2
+
3
+ Make Rails 4+ handle .md templates, with optional preprocessing of ERB, HAML, etc. Easily configurable; uses RedCarpet. Also performs syntax highlighting via CodeRay.
4
+
5
+ ## Usage
6
+
7
+ Just create views as `some_action.html.md` instead of `some_action.html.erb`.
8
+
9
+
10
+ By default also strips all HTML comments from the output. This can cause issues with inline Javascript or otherwise be undesired. To disable, add the following to an initializer:
11
+
12
+ MarkdownViews.strip_comments = false
13
+
14
+ By default, all .md files are preprocessed with ERB (making them effectively .md.erb files). This can be changed or disabled by setting a different template handler or setting to nil, respectively.
15
+
16
+ MarkdownViews.preprocessor = :erb
17
+ MarkdownViews.preprocessor = nil
18
+
19
+ RedCarpet's rendering can be configured. Both rendering options and markdown options can be set. See RedCarpet's documentation for available options.
20
+
21
+ MarkdownViews.markdown_opts.merge! fenced_code_blocks: false
22
+
23
+ MarkdownViews.rendering_opts.merge! link_attributes: {'data-popup'=> true}
24
+
25
+ Likewise, CodeRay can be configured too:
26
+
27
+ MarkdownViews.coderay_opts.merge! line_numbers: true
28
+
29
+ The default CSS from CodeRay is made available via the asset pipeline. To use it, add this to your `application.css`:
30
+
31
+ *= require coderay
32
+
33
+
34
+ ### Helper
35
+
36
+ MarkdownViews also includes a simple Markdown rendering helper. It uses the app-wide config already defined (see above).
37
+
38
+ <%= markdown('## Some markdown text') %>
39
+
40
+ <%= markdown do %>
41
+ ## Some markdown text
42
+ <% end %>
43
+
44
+ ## Installation
45
+
46
+ Add this line to your application's Gemfile:
47
+
48
+ gem 'markdown_views'
49
+
50
+ And then execute:
51
+
52
+ $ bundle
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it ( http://github.com/<my-github-username>/markdown_views/fork )
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :generate_stylesheet do
4
+ `coderay stylesheet > app/assets/stylesheets/coderay.css`
5
+ end
@@ -0,0 +1,131 @@
1
+ .CodeRay {
2
+ background-color: hsl(0,0%,95%);
3
+ border: 1px solid silver;
4
+ color: black;
5
+ }
6
+ .CodeRay pre {
7
+ margin: 0px;
8
+ }
9
+
10
+ span.CodeRay { white-space: pre; border: 0px; padding: 2px; }
11
+
12
+ table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px; }
13
+ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
14
+
15
+ .CodeRay .line-numbers {
16
+ background-color: hsl(180,65%,90%);
17
+ color: gray;
18
+ text-align: right;
19
+ -webkit-user-select: none;
20
+ -moz-user-select: none;
21
+ user-select: none;
22
+ }
23
+ .CodeRay .line-numbers a {
24
+ background-color: hsl(180,65%,90%) !important;
25
+ color: gray !important;
26
+ text-decoration: none !important;
27
+ }
28
+ .CodeRay .line-numbers pre {
29
+ word-break: normal;
30
+ }
31
+ .CodeRay .line-numbers a:target { color: blue !important; }
32
+ .CodeRay .line-numbers .highlighted { color: red !important; }
33
+ .CodeRay .line-numbers .highlighted a { color: red !important; }
34
+ .CodeRay span.line-numbers { padding: 0px 4px; }
35
+ .CodeRay .line { display: block; float: left; width: 100%; }
36
+ .CodeRay .code { width: 100%; }
37
+
38
+ .CodeRay .debug { color: white !important; background: blue !important; }
39
+
40
+ .CodeRay .annotation { color:#007 }
41
+ .CodeRay .attribute-name { color:#b48 }
42
+ .CodeRay .attribute-value { color:#700 }
43
+ .CodeRay .binary { color:#549 }
44
+ .CodeRay .binary .char { color:#325 }
45
+ .CodeRay .binary .delimiter { color:#325 }
46
+ .CodeRay .char { color:#D20 }
47
+ .CodeRay .char .content { color:#D20 }
48
+ .CodeRay .char .delimiter { color:#710 }
49
+ .CodeRay .class { color:#B06; font-weight:bold }
50
+ .CodeRay .class-variable { color:#369 }
51
+ .CodeRay .color { color:#0A0 }
52
+ .CodeRay .comment { color:#777 }
53
+ .CodeRay .comment .char { color:#444 }
54
+ .CodeRay .comment .delimiter { color:#444 }
55
+ .CodeRay .constant { color:#036; font-weight:bold }
56
+ .CodeRay .decorator { color:#B0B }
57
+ .CodeRay .definition { color:#099; font-weight:bold }
58
+ .CodeRay .delimiter { color:black }
59
+ .CodeRay .directive { color:#088; font-weight:bold }
60
+ .CodeRay .docstring { color:#D42; }
61
+ .CodeRay .doctype { color:#34b }
62
+ .CodeRay .done { text-decoration: line-through; color: gray }
63
+ .CodeRay .entity { color:#800; font-weight:bold }
64
+ .CodeRay .error { color:#F00; background-color:#FAA }
65
+ .CodeRay .escape { color:#666 }
66
+ .CodeRay .exception { color:#C00; font-weight:bold }
67
+ .CodeRay .float { color:#60E }
68
+ .CodeRay .function { color:#06B; font-weight:bold }
69
+ .CodeRay .function .delimiter { color:#059 }
70
+ .CodeRay .function .content { color:#037 }
71
+ .CodeRay .global-variable { color:#d70 }
72
+ .CodeRay .hex { color:#02b }
73
+ .CodeRay .id { color:#33D; font-weight:bold }
74
+ .CodeRay .include { color:#B44; font-weight:bold }
75
+ .CodeRay .inline { background-color: hsla(0,0%,0%,0.07); color: black }
76
+ .CodeRay .inline-delimiter { font-weight: bold; color: #666 }
77
+ .CodeRay .instance-variable { color:#33B }
78
+ .CodeRay .integer { color:#00D }
79
+ .CodeRay .imaginary { color:#f00 }
80
+ .CodeRay .important { color:#D00 }
81
+ .CodeRay .key { color: #606 }
82
+ .CodeRay .key .char { color: #60f }
83
+ .CodeRay .key .delimiter { color: #404 }
84
+ .CodeRay .keyword { color:#080; font-weight:bold }
85
+ .CodeRay .label { color:#970; font-weight:bold }
86
+ .CodeRay .local-variable { color:#950 }
87
+ .CodeRay .map .content { color:#808 }
88
+ .CodeRay .map .delimiter { color:#40A}
89
+ .CodeRay .map { background-color:hsla(200,100%,50%,0.06); }
90
+ .CodeRay .namespace { color:#707; font-weight:bold }
91
+ .CodeRay .octal { color:#40E }
92
+ .CodeRay .operator { }
93
+ .CodeRay .predefined { color:#369; font-weight:bold }
94
+ .CodeRay .predefined-constant { color:#069 }
95
+ .CodeRay .predefined-type { color:#0a8; font-weight:bold }
96
+ .CodeRay .preprocessor { color:#579 }
97
+ .CodeRay .pseudo-class { color:#00C; font-weight:bold }
98
+ .CodeRay .regexp { background-color:hsla(300,100%,50%,0.06); }
99
+ .CodeRay .regexp .content { color:#808 }
100
+ .CodeRay .regexp .delimiter { color:#404 }
101
+ .CodeRay .regexp .modifier { color:#C2C }
102
+ .CodeRay .reserved { color:#080; font-weight:bold }
103
+ .CodeRay .shell { background-color:hsla(120,100%,50%,0.06); }
104
+ .CodeRay .shell .content { color:#2B2 }
105
+ .CodeRay .shell .delimiter { color:#161 }
106
+ .CodeRay .string { background-color:hsla(0,100%,50%,0.05); }
107
+ .CodeRay .string .char { color: #b0b }
108
+ .CodeRay .string .content { color: #D20 }
109
+ .CodeRay .string .delimiter { color: #710 }
110
+ .CodeRay .string .modifier { color: #E40 }
111
+ .CodeRay .symbol { color:#A60 }
112
+ .CodeRay .symbol .content { color:#A60 }
113
+ .CodeRay .symbol .delimiter { color:#740 }
114
+ .CodeRay .tag { color:#070; font-weight:bold }
115
+ .CodeRay .type { color:#339; font-weight:bold }
116
+ .CodeRay .value { color: #088 }
117
+ .CodeRay .variable { color:#037 }
118
+
119
+ .CodeRay .insert { background: hsla(120,100%,50%,0.12) }
120
+ .CodeRay .delete { background: hsla(0,100%,50%,0.12) }
121
+ .CodeRay .change { color: #bbf; background: #007 }
122
+ .CodeRay .head { color: #f8f; background: #505 }
123
+ .CodeRay .head .filename { color: white; }
124
+
125
+ .CodeRay .delete .eyecatcher { background-color: hsla(0,100%,50%,0.2); border: 1px solid hsla(0,100%,45%,0.5); margin: -1px; border-bottom: none; border-top-left-radius: 5px; border-top-right-radius: 5px; }
126
+ .CodeRay .insert .eyecatcher { background-color: hsla(120,100%,50%,0.2); border: 1px solid hsla(120,100%,25%,0.5); margin: -1px; border-top: none; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; }
127
+
128
+ .CodeRay .insert .insert { color: #0c0; background:transparent; font-weight:bold }
129
+ .CodeRay .delete .delete { color: #c00; background:transparent; font-weight:bold }
130
+ .CodeRay .change .change { color: #88f }
131
+ .CodeRay .head .head { color: #f4f }
@@ -0,0 +1,12 @@
1
+ module MarkdownViewsHelper
2
+
3
+ def markdown(source=nil)
4
+ if block_given?
5
+ source = capture do
6
+ yield
7
+ end.strip_heredoc
8
+ end
9
+ MarkdownViews::Renderer.render(source)
10
+ end
11
+
12
+ end
@@ -0,0 +1,11 @@
1
+ # require 'active_support/core_ext/module/attribute_accessors'
2
+ require 'action_view'
3
+ require 'cgi'
4
+ require 'coderay'
5
+ require 'redcarpet'
6
+
7
+ %w(config engine handler renderer version).each do |f|
8
+ require "markdown_views/#{f}"
9
+ end
10
+
11
+ ActionView::Template.register_template_handler(:md, MarkdownViews::Handler)
@@ -0,0 +1,38 @@
1
+ module MarkdownViews
2
+ mattr_accessor :strip_comments
3
+ self.strip_comments = true
4
+
5
+ mattr_accessor :preprocessor
6
+ self.preprocessor = :erb
7
+
8
+ mattr_accessor :rendering_opts
9
+ self.rendering_opts = {
10
+ # filter_html: true,
11
+ hard_wrap: true,
12
+ # link_attributes: {'data-popup'=> true},
13
+ # no_styles: true,
14
+ # safe_links_only: true,
15
+ }
16
+
17
+ mattr_accessor :markdown_opts
18
+ self.markdown_opts = {
19
+ autolink: true,
20
+ disable_indented_code_blocks: true,
21
+ fenced_code_blocks: true,
22
+ lax_spacing: true,
23
+ no_intra_emphasis: true,
24
+ space_after_headers: true,
25
+ strikethrough: true,
26
+ tables: true,
27
+ }
28
+
29
+ mattr_accessor :coderay_opts
30
+ self.coderay_opts = {
31
+ bold_every: false,
32
+ css: :class,
33
+ line_number_anchors: false,
34
+ line_numbers: false,
35
+ }
36
+
37
+ end
38
+
@@ -0,0 +1,4 @@
1
+ module MarkdownViews
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,22 @@
1
+ module MarkdownViews
2
+ class Handler
3
+ class << self
4
+
5
+ def call(template)
6
+ source = preprocessor.call(template)
7
+
8
+ <<-R1
9
+ MarkdownViews::Renderer.render(begin;#{source};end)
10
+ R1
11
+ end
12
+
13
+ def preprocessor
14
+ @@preprocessor ||= begin
15
+ pp = MarkdownViews.preprocessor || :raw
16
+ ActionView::Template.registered_template_handler(pp) || raise('Unknown template handler')
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,52 @@
1
+ module MarkdownViews
2
+ class Renderer
3
+ class << self
4
+
5
+ def render(template)
6
+ out = template.to_s
7
+ out = strip_comments(out) if MarkdownViews.strip_comments
8
+ out = renderer.render(out)
9
+ out = strip_comments(out) if MarkdownViews.strip_comments
10
+ out.html_safe
11
+ end
12
+
13
+ def renderer
14
+ @@renderer ||= begin
15
+ r = ExtendedMarkdownHtml.new MarkdownViews.rendering_opts
16
+ Redcarpet::Markdown.new r, MarkdownViews.markdown_opts
17
+ end
18
+ end
19
+
20
+ def strip_comments(input)
21
+ input.gsub(/[ \t\r\n\f]*<!--(.*?)-->*/m, '')
22
+ end
23
+
24
+ end
25
+ end
26
+
27
+ class ExtendedMarkdownHtml < Redcarpet::Render::HTML
28
+ include Redcarpet::Render::SmartyPants
29
+
30
+ def block_code(text, language)
31
+ language ||= 'text'
32
+ html = CGI::unescapeHTML(text).sub(/\A[ \t\n\r]+/, '').sub(/[ \t\n\r]+\Z/, '')
33
+ cr = CodeRay.scan(html, language).html(MarkdownViews.coderay_opts)
34
+ %Q{<pre class="lang-#{language.to_s.gsub(/[^a-z0-9]/,'')}"><code class="CodeRay">#{cr.chomp}</code></pre>}
35
+ end
36
+
37
+ def table(header, body)
38
+ <<-TBL
39
+ <div class="table-responsive">
40
+ <table class="table">
41
+ <thead>
42
+ #{header}
43
+ </thead>
44
+ <tbody>
45
+ #{body}
46
+ </tbody>
47
+ </table>
48
+ </div>
49
+ TBL
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module MarkdownViews
2
+ VERSION = '0.4.0'
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'markdown_views/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "markdown_views"
8
+ spec.version = MarkdownViews::VERSION
9
+ spec.authors = ["thomas morgan"]
10
+ spec.email = ["tm@iprog.com"]
11
+ spec.summary = %q{Add .md template handler to Rails.}
12
+ spec.description = %q{Makes Rails handle .md templates, with optional preprocessing of ERB, HAML, etc. Easily configurable; uses RedCarpet & CodeRay.}
13
+ spec.homepage = "https://github.com/zarqman/markdown_views"
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_dependency 'redcarpet', '~> 3.1'
22
+ spec.add_dependency 'coderay', '~> 1.1'
23
+ spec.add_dependency 'actionpack', '>= 4.0', '< 6'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.5"
26
+ spec.add_development_dependency "rake"
27
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdown_views
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - thomas morgan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redcarpet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coderay
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: actionpack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '6'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '4.0'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '6'
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.5'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.5'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description: Makes Rails handle .md templates, with optional preprocessing of ERB,
90
+ HAML, etc. Easily configurable; uses RedCarpet & CodeRay.
91
+ email:
92
+ - tm@iprog.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - ".gitignore"
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - app/assets/stylesheets/coderay.css
103
+ - app/helpers/markdown_views_helper.rb
104
+ - lib/markdown_views.rb
105
+ - lib/markdown_views/config.rb
106
+ - lib/markdown_views/engine.rb
107
+ - lib/markdown_views/handler.rb
108
+ - lib/markdown_views/renderer.rb
109
+ - lib/markdown_views/version.rb
110
+ - markdown_views.gemspec
111
+ homepage: https://github.com/zarqman/markdown_views
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.6.12
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Add .md template handler to Rails.
135
+ test_files: []