redcarpet-abbreviations 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d4882809ef4ce82e8cad61c1089ff79d9b31b321
4
+ data.tar.gz: 535244a1de7a5dde8c6ec838c794270e30e6d164
5
+ SHA512:
6
+ metadata.gz: 90dc5b65b3d4304df9e257077738659ce607fde6dce5e0de294e4d03accb3ea3209915d5d87104313a709c7559a0a01c12152ef5fd5162df0b3e812bf79f10f2
7
+ data.tar.gz: 4a97381b9f53c8a2f1d8f6fa5e2e8fc81fceb3725ca7a0b2dd1bbe79a301957fda9ecaa10c64a98ea45f4d5b4dcba18e55d5bb7a820215675f543d723ebf6775
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in redcarpet-abbreviations.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Brandon Weiss
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,69 @@
1
+ # Redcarpet::Abbreviations
2
+
3
+ An extension for Redcarpet that supports abbreviations. So this:
4
+
5
+ ```
6
+ I'm pretty sure I'm not using this acronym right but hey YOLO.
7
+
8
+ *[YOLO]: You Only Live Once
9
+ ```
10
+
11
+ Becomes this:
12
+
13
+ ```
14
+ I'm pretty sure I'm not using this acronym right but hey <abbr title="You Only Live Once">YOLO</abbr>.
15
+ ```
16
+
17
+ If you're thinking this would be better in Redcarpet, [yes I totally agree](https://github.com/vmg/redcarpet/issues/197), but I don't know C.
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem "redcarpet-abbreviations"
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install redcarpet-abbreviations
34
+
35
+ ## Usage
36
+
37
+ Just include it in your renderer.
38
+
39
+ ```ruby
40
+ class HTMLWithAbbreviations < Redcarpet::Render::HTML
41
+
42
+ include Redcarpet::Render::HTMLAbbreviations
43
+
44
+ end
45
+ ```
46
+
47
+ Remember to call `super` if your renderer has its own `preprocess` method, otherwise it will override the included `preprocess` method.
48
+
49
+ ```ruby
50
+ class HTMLWithAbbreviations < Redcarpet::Render::HTML
51
+
52
+ include Redcarpet::Render::HTMLAbbreviations
53
+
54
+ def preprocess(document)
55
+ document = super(document)
56
+
57
+ # ...
58
+ end
59
+
60
+ end
61
+ ```
62
+
63
+ ## Contributing
64
+
65
+ 1. Fork it ( https://github.com/brandonweiss/redcarpet-abbreviations/fork )
66
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
67
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
68
+ 4. Push to the branch (`git push origin my-new-feature`)
69
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.pattern = "test/**/*_test.rb"
6
+ end
7
+
8
+ task :default => :test
@@ -0,0 +1,5 @@
1
+ module Redcarpet
2
+ module Abbreviations
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ module Redcarpet
2
+ module Render
3
+ module HTMLAbbreviations
4
+
5
+ def preprocess(document)
6
+ abbreviations = document.scan(/^\*\[([A-Z]+)\]: (.+)$/)
7
+ abbreviations = Hash[*abbreviations.flatten]
8
+
9
+ if abbreviations.any?
10
+ document.gsub!(/^\*\[([A-Z]+)\]: (.+)$/, "")
11
+ document.rstrip!
12
+
13
+ abbreviations.each do |key, value|
14
+ html = <<-EOS.strip
15
+ <abbr title="#{value}">#{key}</abbr>
16
+ EOS
17
+
18
+ document.gsub!(acronym_regexp(key), html)
19
+ end
20
+ end
21
+
22
+ document
23
+ end
24
+
25
+ def acronym_regexp(acronym)
26
+ /\b#{acronym}\b/
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,2 @@
1
+ require "redcarpet/abbreviations/version"
2
+ require "redcarpet/render/html_abbreviations"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "redcarpet/abbreviations/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "redcarpet-abbreviations"
8
+ spec.version = Redcarpet::Abbreviations::VERSION
9
+ spec.authors = ["Brandon Weiss"]
10
+ spec.email = ["brandon@anti-pattern.com"]
11
+ spec.summary = %q{An extension for Redcarpet that supports abbreviations.}
12
+ spec.description = %q{An extension for Redcarpet that supports abbreviations.}
13
+ spec.homepage = ""
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_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,46 @@
1
+ require File.expand_path("../../../test_helper", __FILE__)
2
+
3
+ describe Redcarpet::Render::HTMLAbbreviations do
4
+
5
+ before do
6
+ @renderer = Class.new do
7
+ include Redcarpet::Render::HTMLAbbreviations
8
+ end
9
+ end
10
+
11
+ describe "#preprocess" do
12
+
13
+ it "converts markdown abbrevations to HTML" do
14
+ markdown = <<-EOS.strip_heredoc
15
+ YOLO
16
+
17
+ *[YOLO]: You Only Live Once
18
+ EOS
19
+
20
+ @renderer.new.preprocess(markdown).must_equal <<-EOS.strip_heredoc.chomp
21
+ <abbr title=\"You Only Live Once\">YOLO</abbr>
22
+ EOS
23
+ end
24
+
25
+ end
26
+
27
+ describe "#acronym_regexp" do
28
+
29
+ it "matches an acronym at the beginning of a line" do
30
+ "FOO bar".must_match @renderer.new.acronym_regexp("FOO")
31
+ end
32
+
33
+ it "matches an acronym at the end of a line" do
34
+ "bar FOO".must_match @renderer.new.acronym_regexp("FOO")
35
+ end
36
+
37
+ it "matches an acronym next to punctuation" do
38
+ ".FOO.".must_match @renderer.new.acronym_regexp("FOO")
39
+ end
40
+
41
+ it "doesn't match an acronym in the middle of a word" do
42
+ "YOLOFOOYOLO".wont_match @renderer.new.acronym_regexp("FOO")
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require "redcarpet-abbreviations"
3
+
4
+ require 'minitest/autorun'
5
+
6
+ class Object
7
+
8
+ def try(*a, &b)
9
+ if a.empty? && block_given?
10
+ yield self
11
+ else
12
+ public_send(*a, &b) if respond_to?(a.first)
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+ class String
19
+
20
+ def strip_heredoc
21
+ indent = scan(/^[ \t]*(?=\S)/).min.try(:size) || 0
22
+ gsub(/^[ \t]{#{indent}}/, '')
23
+ end
24
+
25
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redcarpet-abbreviations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Weiss
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: An extension for Redcarpet that supports abbreviations.
42
+ email:
43
+ - brandon@anti-pattern.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/redcarpet-abbreviations.rb
54
+ - lib/redcarpet/abbreviations/version.rb
55
+ - lib/redcarpet/render/html_abbreviations.rb
56
+ - redcarpet-abbreviations.gemspec
57
+ - test/redcarpet/render/html_abbreviations_test.rb
58
+ - test/test_helper.rb
59
+ homepage: ''
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: An extension for Redcarpet that supports abbreviations.
83
+ test_files:
84
+ - test/redcarpet/render/html_abbreviations_test.rb
85
+ - test/test_helper.rb