emd 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ad888db5ed6ebd058f0109679ed0c254a8c16983
4
- data.tar.gz: e34c2df334b51cc6428c99e68080b77d3b34f124
2
+ SHA256:
3
+ metadata.gz: dd3ac910c3743f48445bbd54b724144707ff45b3e3058d8b4dcb3f755344fd18
4
+ data.tar.gz: feca68b0ce825d203f547c0da3a09d098065098016d117dcbbbcdced04198b2f
5
5
  SHA512:
6
- metadata.gz: 337f029b28177e7302419b9731d9e6fa3356a0cad06f7f5931b2a9c737f3c9834208ba4e2393e97c5b01552b8f9f9f5ce8385fca7817038dfe0db4d6d5aa2be4
7
- data.tar.gz: 602cf0d3b273df5fd10df3efbee9c50d44e6a993ef21a12db88a2dde77ca1fe21254baca67d201ce0951fc492ab2f0b3b9ebaa1bbdf5f943e629ec2eba0f0b88
6
+ metadata.gz: cef74a0aa74e565711dc88a9a7fc3f0a77471d4bf1050f89827b438e862df197f4a8fe01b68f534ca257c64ecf172be16e73e8b9024367c75023fda7cbaf2db0
7
+ data.tar.gz: 66561776e714513d4fdd161a8e909daa802d5d39456e56771c674d4e99b284a9a645268ab488e2c75d02c21e698de8bce4448d83852a8dcd2604fab8b018e87b
data/README.md CHANGED
@@ -1,49 +1,106 @@
1
- # emd
1
+ # Embedded Markdown [![Gem Version](https://badge.fury.io/rb/emd.svg)](https://badge.fury.io/rb/emd)
2
2
 
3
- Embedded Markdown is created so that I can use markdown within my own rails projects.
3
+ Embedded Markdown uses a Rails engine and a simple initializer to initiate a markdown template handler with the help of Redcarpet and syntax highlighting from Coderay.
4
4
 
5
- Embedded Markdown uses a rails engine and a simple initializer to initiate a template handler for markdown using redcarpet.
5
+ The motivation is to reuse Markdown file in several of my Rails projects.
6
6
 
7
- Special thanks to [these folks](http://stackoverflow.com/questions/4163560/how-can-i-automatically-render-partials-using-markdown-in-rails-3/10131299#10131299
8
- ) for making emd possible
9
-
10
- ## Example repo
11
-
12
- TODO
7
+ - 😊 Reuse Markdown in Rails products
8
+ - 📝 Allow copywriters & marketers to be involved in building your content easily
9
+ - 📝 Allows you to focus on the content instead of the webpage structure.
10
+ - 🙌 Supports syntax highlighting via Coderay
13
11
 
14
12
  ## Installation
15
13
 
16
14
  Add this two lines to your application's Gemfile:
17
15
 
18
16
  ```ruby
17
+ gem 'coderay' #optional for Syntax Highlighting
19
18
  gem 'redcarpet'
20
19
  gem 'emd'
21
20
  ```
22
- > emd depends on redcarpet for markdown rendering
21
+ > emd depends on Redcarpet for Markdown rendering
23
22
 
24
23
  And then execute:
25
24
 
26
25
  $ bundle
27
26
 
28
- Or install it yourself as:
27
+ ## Usage
29
28
 
30
- $ gem install emd
29
+ ### A Markdown view
31
30
 
32
- ## Usage
31
+ 1. Create a view called app/view/home/markdown.html.md and add the following sample Markdown.
32
+
33
+ ```markdown
34
+ ## This is a sample Markdown code
35
+ - [google](http://google.com)
36
+ - [emd](https://github.com/ytbryan/emd/)
37
+ ```
38
+
39
+ 1. Generate a home controller using the following command `rails generate controller home`
33
40
 
34
- create a partial app/view/frontpages/`_component.html.md`
41
+ 1. At route.rb, add the following line:
42
+ ```
43
+ get '/markdown', to: 'home#markdown'
44
+ ```
45
+ 1. Finally, visit the markdown view at [http://localhost:3000/markdown](http://localhost:3000/markdown)
35
46
 
36
- ```markdown
37
- ### This is a component
38
47
 
39
- - This is item 1
40
- - This is iiem 2
41
- - [This is a link to google] (http://google.com)
48
+ ### A Markdown partial
42
49
 
50
+ 1. Create a partial app/view/home/`_component.html.md`
51
+
52
+ ```markdown
53
+ ### This is a component
54
+
55
+ - This is item 1
56
+ - This is iiem 2
57
+ - [This is a link to google] (http://google.com)
58
+ ```
59
+
60
+ 1. Then, use this partial using `<%= render "component" %>` within any view like index.html.erb
61
+
62
+ ### Syntax Highlighting
63
+
64
+ To support syntax highlighting, add `coderay` to Gemfile as shown below:
65
+
66
+ ```ruby
67
+ gem 'coderay'
43
68
  ```
69
+ Remember to run `bundle install`.
44
70
 
45
- Then, use this partial using <%= render "component" %> within any view like index.html.erb
71
+ This will turn all the code block into:
46
72
 
73
+ ```ruby
74
+ ```ruby
75
+ puts "something"
76
+ ```
77
+ ```
78
+
79
+ ```ruby
80
+ puts "something"
81
+ ```
82
+
83
+ ### Control which extensions Redcarpet uses
84
+
85
+ `emd` assumes some sane redcarpet extension use (see redcarpets options [here](https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use) and [here](https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch)). If you need to overwrite these in your Rails app, create a file `config/initializers/markdown_template_handler.rb` to overwrite the defaults from [config/initializers/markdown_template_handler.rb](config/initializers/markdown_template_handler.rb) like this:
86
+
87
+ ```
88
+ module MarkdownTemplateHandler
89
+ def self.call(template)
90
+ compiled_source = erb.call(template)
91
+ "Redcarpet::Markdown.new(Redcarpet::Render::HTML,
92
+ no_intra_emphasis: true,
93
+ fenced_code_blocks: true,
94
+ # I actually like that, so commented it out:
95
+ # disable_indented_code_blocks: true,
96
+ space_after_headers: true,
97
+ prettify: true,
98
+ tables: true,
99
+ with_toc_data: true,
100
+ autolink: true).render(begin;#{compiled_source};end).html_safe"
101
+ end
102
+ end
103
+ ```
47
104
 
48
105
  ## Development
49
106
 
@@ -53,9 +110,13 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
53
110
 
54
111
  ## Contributing
55
112
 
56
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/emd. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
113
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ytbryan/emd. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
57
114
 
58
115
 
59
116
  ## License
60
117
 
61
118
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
119
+
120
+
121
+ Special thanks to [these folks](http://stackoverflow.com/questions/4163560/how-can-i-automatically-render-partials-using-markdown-in-rails-3/10131299#10131299
122
+ ) for making emd possible
@@ -0,0 +1,5 @@
1
+ module EmdHelper
2
+ def emd content
3
+ Markdown.new(content).to_html.html_safe
4
+ end
5
+ end
@@ -1,20 +1,34 @@
1
- module MarkdownTemplateHandler
1
+ class CodeRayify < Redcarpet::Render::HTML
2
+ def block_code(code, language)
3
+ if Gem.loaded_specs.has_key?('coderay')
4
+ CodeRay.scan(code, language).div
5
+ else
6
+ %(<pre>#{code}</pre>)
7
+ end
8
+ end
9
+ end
10
+
11
+ module MarkdownTemplateHandler
2
12
  def self.erb
3
13
  @erb ||= ActionView::Template.registered_template_handler(:erb)
4
14
  end
5
15
 
6
16
  def self.call(template)
7
17
  compiled_source = erb.call(template)
8
- "Redcarpet::Markdown.new(Redcarpet::Render::HTML,
9
- no_intra_emphasis: true,
10
- fenced_code_blocks: true,
11
- space_after_headers: true,
12
- smartypants: true,
13
- disable_indented_code_blocks: true,
14
- prettify: true,
15
- tables: true,
16
- with_toc_data: true,
17
- autolink: true).render(begin;#{compiled_source};end).html_safe"
18
+
19
+ %(Redcarpet::Markdown.new(CodeRayify.new(:filter_html => true,
20
+ :hard_wrap => true),
21
+ no_intra_emphasis: true,
22
+ fenced_code_blocks: true,
23
+ space_after_headers: true,
24
+ smartypants: true,
25
+ disable_indented_code_blocks: true,
26
+ prettify: true,
27
+ tables: true,
28
+ with_toc_data: true,
29
+ autolink: true
30
+ ).render(begin;#{compiled_source};end).html_safe)
31
+
18
32
  end
19
33
  end
20
34
 
data/lib/emd.rb CHANGED
@@ -1,22 +1,6 @@
1
1
  require "emd/version"
2
- require "thor"
3
2
 
4
3
  module Emd
5
-
6
4
  class Engine < ::Rails::Engine
7
5
  end
8
-
9
- class Base < Thor
10
-
11
- desc :test, 'test this'
12
- # method_option :group, type: :boolean, aliases: '-g'
13
- # method_option :load, type: :string, aliases: '-l'
14
- # method_option :save, type: :string, aliases: '-s'
15
- # method_option :force, type: :boolean, aliases: '-f'
16
-
17
- def test(arg = nil)
18
- puts "test"
19
- end
20
-
21
- end
22
6
  end
data/lib/emd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Emd
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Lim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-29 00:00:00.000000000 Z
11
+ date: 2019-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 3.4.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 3.4.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coderay
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.1.2
55
69
  description: mbedded markdown template for Ruby on Rails
56
70
  email:
57
71
  - ytbryan@gmail.com
@@ -60,11 +74,12 @@ extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
76
  - README.md
77
+ - app/helpers/emd_helper.rb
63
78
  - config/initializers/markdown_template_handler.rb
64
79
  - lib/emd.rb
65
80
  - lib/emd/post_message.rb
66
81
  - lib/emd/version.rb
67
- homepage: ''
82
+ homepage: https://github.com/ytbryan/emd
68
83
  licenses:
69
84
  - MIT
70
85
  metadata: {}
@@ -86,8 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
101
  - !ruby/object:Gem::Version
87
102
  version: '0'
88
103
  requirements: []
89
- rubyforge_project:
90
- rubygems_version: 2.5.2
104
+ rubygems_version: 3.0.4
91
105
  signing_key:
92
106
  specification_version: 4
93
107
  summary: Embedded markdown template for Ruby on Rails