markdown-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/License.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2012 Jo Liss
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # markdown-rails
2
+
3
+ This gem allows you to write static Rails views and partials using the
4
+ [Markdown](http://daringfireball.net/projects/markdown/syntax) syntax. No more
5
+ editing prose in HTML!
6
+
7
+ ## Usage
8
+
9
+ Add the following to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'markdown-rails'
13
+ ```
14
+
15
+ Now add views or partials ending in `.md` or `.markdown`.
16
+
17
+ ## Examples
18
+
19
+ ### Static View
20
+
21
+ In `app/views/home/about.html.md`:
22
+
23
+ ```markdown
24
+ # About This Site
25
+
26
+ *Markdown code goes here ...*
27
+ ```
28
+
29
+ Keep in mind that unlike static files dropped in `public`, you still need a
30
+ matching route, such as `get ':action', :controller => :home`, to route
31
+ `/about` to `home#about`.
32
+
33
+ ### Static Partial
34
+
35
+ In `app/views/posts/edit.html.erb`:
36
+
37
+ ```erb
38
+ <form>... dynamic code goes here ...</form>
39
+ <div class="help">
40
+ <%= render :partial => "posts/edit_help" %>
41
+ </div>
42
+ ```
43
+
44
+ In `app/views/posts/_edit_help.html.md`:
45
+
46
+ ```markdown
47
+ ## How To Edit
48
+
49
+ This text is written in **Markdown**. :-)
50
+ ```
51
+
52
+ ## Configuration
53
+
54
+ By default markdown-rails uses the
55
+ [RDiscount](https://github.com/rtomayko/rdiscount) parser. You can change this
56
+ by calling `config.render` like so:
57
+
58
+ ```ruby
59
+ Markdown::Rails.configure do |config|
60
+ config.render do |markdown_source|
61
+ # Return compiled HTML here ...
62
+ end
63
+ end
64
+ ```
65
+
66
+ You might in particular want to use
67
+ [Redcarpet](https://github.com/tanoku/redcarpet), which allows you to enable
68
+ various aspects of [GitHub Flavored
69
+ Markdown](http://github.github.com/github-flavored-markdown/) through its
70
+ parser options. To do so, add the `redcarpet` gem to your Gemfile, and add the
71
+ following into a `config/initializers/markdown.rb` file:
72
+
73
+ ```ruby
74
+ Markdown::Rails.configure do |config|
75
+ markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
76
+ :fenced_code_blocks => true,
77
+ :autolink => true,
78
+ ... etc ...)
79
+ config.render do |markdown_source|
80
+ markdown.render(markdown_source)
81
+ end
82
+ end
83
+ ```
84
+
85
+ ## Security
86
+
87
+ Despite Markdown being a static language, you should not use this gem to
88
+ process untrusted Markdown views (or partials). In other words, do not add
89
+ Markdown views from a source if you wouldn't trust Erb views from them.
90
+
91
+ ## Limitations
92
+
93
+ * It's not possible to embed Ruby code in the Markdown code. Unfortunately,
94
+ you cannot simply chain template handlers (`.md.erb`) like you can with
95
+ asset handlers. (This is reasonable if you consider that unlike assets,
96
+ templates are precompiled not into strings but into Ruby code, which is
97
+ then called every time the template is served.) Still, the performance of
98
+ modern Markdown parsers is good enough that you can reparse the Markdown on
99
+ every template view without precompiling, so this should be possible in
100
+ principle.
101
+
102
+ In the meantime, you can [use HAML's :markdown
103
+ filter](http://stackoverflow.com/a/4418389/525872) to the same effect.
104
+
105
+ * The only truly Markdown-specific code in the source is
106
+ `RDiscount.new(markdown_source).to_html` and the `.md`/`.markdown` file
107
+ name extensions. This gem can and should be generalized into a
108
+ general-purpose static template gem, so that you can easily use other
109
+ static templating languages in Rails. Perhaps
110
+ [tilt](https://github.com/rtomayko/tilt) will come in useful.
@@ -0,0 +1 @@
1
+ require 'markdown/rails/engine'
@@ -0,0 +1,38 @@
1
+ require 'rdiscount'
2
+ require 'action_view'
3
+
4
+ module Markdown
5
+ module Rails
6
+ class Handler
7
+ def initialize
8
+ end
9
+
10
+ def call(template)
11
+ # Return Ruby code that returns the compiled template
12
+ Markdown::Rails.renderer.call(template.source).inspect + '.html_safe'
13
+ end
14
+ end
15
+
16
+ class <<self
17
+ def configure
18
+ yield self
19
+ end
20
+
21
+ attr_accessor :renderer
22
+
23
+ def render(&block)
24
+ self.renderer = block
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ Markdown::Rails.configure do |config|
31
+ config.render do |markdown_source|
32
+ RDiscount.new(markdown_source).to_html
33
+ end
34
+ end
35
+
36
+ handler = Markdown::Rails::Handler.new
37
+ ActionView::Template.register_template_handler(:md, handler)
38
+ ActionView::Template.register_template_handler(:markdown, handler)
@@ -0,0 +1,5 @@
1
+ module Markdown
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/markdown/rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "markdown-rails"
6
+ s.version = Markdown::Rails::VERSION
7
+ s.authors = ["Jo Liss"]
8
+ s.email = ["joliss42@gmail.com"]
9
+ s.homepage = "https://github.com/joliss/markdown-rails"
10
+ s.summary = "Markdown as a Rails templating language"
11
+ s.description = "Markdown as a static templating language for Rails views and partials"
12
+
13
+ s.required_rubygems_version = ">= 1.3.6"
14
+
15
+ s.add_dependency "rails", ">= 3.0.0"
16
+ s.add_dependency "rdiscount", [">= 1.6.8", "< 2.0"]
17
+
18
+ s.files = `git ls-files`.split("\n").reject { |f| f =~ /^testapp/ }
19
+ s.executables = `git ls-files`.split("\n").select { |f| f =~ /^bin/ }
20
+ s.require_path = 'lib'
21
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdown-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jo Liss
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &17430280 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *17430280
25
+ - !ruby/object:Gem::Dependency
26
+ name: rdiscount
27
+ requirement: &17429740 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.8
33
+ - - <
34
+ - !ruby/object:Gem::Version
35
+ version: '2.0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: *17429740
39
+ description: Markdown as a static templating language for Rails views and partials
40
+ email:
41
+ - joliss42@gmail.com
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - .gitignore
47
+ - Gemfile
48
+ - License.txt
49
+ - README.md
50
+ - lib/markdown-rails.rb
51
+ - lib/markdown/rails/engine.rb
52
+ - lib/markdown/rails/version.rb
53
+ - markdown-rails.gemspec
54
+ homepage: https://github.com/joliss/markdown-rails
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: 1.3.6
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.11
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Markdown as a Rails templating language
78
+ test_files: []
79
+ has_rdoc: