mustdown 0.0.1
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.
- data/MIT-LICENSE +20 -0
- data/README.md +119 -0
- data/Rakefile +29 -0
- data/app/helpers/mustdown/mustdown_helper.rb +21 -0
- data/lib/mustdown/engine.rb +13 -0
- data/lib/mustdown/version.rb +3 -0
- data/lib/mustdown.rb +39 -0
- data/lib/tasks/mustdown_tasks.rake +4 -0
- metadata +139 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# Mustdown
|
2
|
+
|
3
|
+
Mustdown provides helpers to ease the use markdown, mustache and both of them.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the gem to your `Gemfile` :
|
8
|
+
|
9
|
+
gem 'mustdown'
|
10
|
+
|
11
|
+
Then call `bundle install` to install it for your application.
|
12
|
+
|
13
|
+
## Provided helpers
|
14
|
+
|
15
|
+
### markdown
|
16
|
+
|
17
|
+
This will render the given text through Markdown.
|
18
|
+
|
19
|
+
``` html_rails
|
20
|
+
<%= markdown "# Hello World" %>
|
21
|
+
```
|
22
|
+
|
23
|
+
Output:
|
24
|
+
|
25
|
+
``` html
|
26
|
+
<h1>Hello World</h1>
|
27
|
+
```
|
28
|
+
|
29
|
+
### mustache
|
30
|
+
|
31
|
+
The `mustache` helper renders a mustache template with the given binding object.
|
32
|
+
|
33
|
+
``` html_rails
|
34
|
+
<%= mustache "Hello {{name}}", name: 'John' %>
|
35
|
+
```
|
36
|
+
|
37
|
+
Output:
|
38
|
+
|
39
|
+
``` html
|
40
|
+
Hello John
|
41
|
+
```
|
42
|
+
|
43
|
+
### mustdown
|
44
|
+
|
45
|
+
This helper is more complex since it provides the two previous helpers in one.
|
46
|
+
|
47
|
+
``` html_rails
|
48
|
+
<%= mustdown "# {{title}}", title: 'Hello World' %>
|
49
|
+
```
|
50
|
+
|
51
|
+
Output:
|
52
|
+
|
53
|
+
``` html
|
54
|
+
<h1>Hello World</h1>
|
55
|
+
```
|
56
|
+
|
57
|
+
## Mustdown configuration
|
58
|
+
|
59
|
+
You can generate a default initializer by calling:
|
60
|
+
|
61
|
+
bundle exec rails generate mustdown:install
|
62
|
+
|
63
|
+
The markdown configuration is provided by Redcarpet. All Redcarpet options are
|
64
|
+
available.
|
65
|
+
|
66
|
+
### Overriding the configuration from the view
|
67
|
+
|
68
|
+
The `markdown` and `mustdown` helpers accept additional parameters for markdown
|
69
|
+
configuration. The settings you pass are merged with the default ones and take
|
70
|
+
precedence.
|
71
|
+
|
72
|
+
``` ruby
|
73
|
+
<%= markdown "**Hello World**", { autolink: false }, { hard_wrap: true} %>
|
74
|
+
```
|
75
|
+
|
76
|
+
## Using with I18n
|
77
|
+
|
78
|
+
A very useful technique is to use templates from I18n.
|
79
|
+
|
80
|
+
Let's take an example. Given the following models in your app:
|
81
|
+
|
82
|
+

|
83
|
+
|
84
|
+
|
85
|
+
Define the following in `config/locales/en.yml`:
|
86
|
+
|
87
|
+
``` yaml
|
88
|
+
en:
|
89
|
+
companies:
|
90
|
+
show:
|
91
|
+
text: |
|
92
|
+
# {{name}}
|
93
|
+
|
94
|
+
{{name}} is a great company ! Here are some of their projects:
|
95
|
+
|
96
|
+
{{#projects}}
|
97
|
+
* [{{title}}]({{url}})
|
98
|
+
{{/projects}}
|
99
|
+
```
|
100
|
+
|
101
|
+
Now we can use it in our show template (located in
|
102
|
+
`app/views/companies/show.html.erb`):
|
103
|
+
|
104
|
+
``` html_rails
|
105
|
+
<%= mustdown t('.text'), @company %>
|
106
|
+
```
|
107
|
+
|
108
|
+
Output:
|
109
|
+
|
110
|
+
``` html
|
111
|
+
<h1>Github</h1>
|
112
|
+
|
113
|
+
<p>Github is a great company ! Here are some of their projects:</p>
|
114
|
+
|
115
|
+
<ul>
|
116
|
+
<li><a href="https://github.com/github/hubot">Hubot</a></li>
|
117
|
+
<li><a href="https://github.com/github/gollum">Gollum</a></li>
|
118
|
+
</ul>
|
119
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Mustdown'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rspec/core/rake_task'
|
24
|
+
|
25
|
+
RSpec::Core::RakeTask.new(:spec)
|
26
|
+
|
27
|
+
task :default => :spec
|
28
|
+
|
29
|
+
Bundler::GemHelper.install_tasks
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Mustdown
|
2
|
+
module MustdownHelper
|
3
|
+
def markdown(content, markdown_extensions = {}, renderer_options = {})
|
4
|
+
md_exts = Mustdown.markdown_extensions.merge(markdown_extensions)
|
5
|
+
renderer_opts = Mustdown.renderer_options.merge(renderer_options)
|
6
|
+
|
7
|
+
renderer = Mustdown.renderer.new(renderer_opts)
|
8
|
+
markdown = Redcarpet::Markdown.new(renderer, md_exts)
|
9
|
+
|
10
|
+
markdown.render(content).html_safe
|
11
|
+
end
|
12
|
+
|
13
|
+
def mustache(template, resource)
|
14
|
+
Mustache.render(template, resource).html_safe
|
15
|
+
end
|
16
|
+
|
17
|
+
def mustdown(template, resource, *markdown_args)
|
18
|
+
markdown mustache(template, resource), *markdown_args
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Mustdown
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
config.generators do |g|
|
4
|
+
g.test_framework :rspec, view_specs: false
|
5
|
+
end
|
6
|
+
|
7
|
+
initializer 'mustdown.action_controller' do |app|
|
8
|
+
ActiveSupport.on_load :action_controller do
|
9
|
+
helper Mustdown::MustdownHelper
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/mustdown.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
require 'redcarpet'
|
4
|
+
require 'mustache'
|
5
|
+
|
6
|
+
require 'mustdown/engine'
|
7
|
+
|
8
|
+
module Mustdown
|
9
|
+
class << self
|
10
|
+
attr_accessor :markdown_extensions
|
11
|
+
attr_accessor :renderer_options
|
12
|
+
attr_accessor :renderer
|
13
|
+
|
14
|
+
def configure
|
15
|
+
yield self
|
16
|
+
end
|
17
|
+
|
18
|
+
def markdown_extensions
|
19
|
+
@markdown_extensions ||= {
|
20
|
+
no_intra_emphasis: true,
|
21
|
+
tables: true,
|
22
|
+
fenced_code_blocks: true,
|
23
|
+
autolink: true,
|
24
|
+
strikethrough: true
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def renderer_options
|
29
|
+
@renderer_options ||= {
|
30
|
+
no_styles: true,
|
31
|
+
safe_links_only: true
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def renderer
|
36
|
+
@renderer ||= Redcarpet::Render::HTML
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mustdown
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Simon COURTOIS
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.1.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: redcarpet
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: mustache
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.99.4
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.99.4
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: sqlite3
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec-rails
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Rails helpers to use Markdown and Mustache all together
|
95
|
+
email:
|
96
|
+
- scourtois+cubyx@cubyx.fr
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- app/helpers/mustdown/mustdown_helper.rb
|
102
|
+
- lib/mustdown/engine.rb
|
103
|
+
- lib/mustdown/version.rb
|
104
|
+
- lib/mustdown.rb
|
105
|
+
- lib/tasks/mustdown_tasks.rake
|
106
|
+
- MIT-LICENSE
|
107
|
+
- Rakefile
|
108
|
+
- README.md
|
109
|
+
homepage: http://github.com/simonc/mustdown
|
110
|
+
licenses: []
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
hash: -1835839034427795028
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
hash: -1835839034427795028
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 1.8.23
|
136
|
+
signing_key:
|
137
|
+
specification_version: 3
|
138
|
+
summary: Rails helpers to use Markdown and Mustache all together
|
139
|
+
test_files: []
|