maruku_snippet 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/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/.rvmrc ADDED
@@ -0,0 +1,3 @@
1
+
2
+ rvm_gemset_create_on_use_flag=1
3
+ rvm 1.9.2@maruku-snippet
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+
2
+ source :rubygems
3
+ #If this is a gem
4
+ #Normal gems go in maruku-snippet.gemspec
5
+ gemspec
6
+
7
+ #development and test not install on heroku deployment
8
+ group :development do
9
+
10
+ end
11
+
12
+ group :test do
13
+ gem "rspec", :require => "spec"
14
+ end
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+
2
+ Copyright (c) 2012, Morgan Prior
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+ * Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in the
11
+ documentation and/or other materials provided with the distribution.
12
+ * Neither the name of the organization nor the
13
+ names of its contributors may be used to endorse or promote products
14
+ derived from this software without specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ maruku-snippet
2
+ ==============
3
+
4
+ Extends MaRuKu markdown parsing to adding .to_html_snippet(lines).
5
+ A simpe way to generate document previews with out breaking links.
6
+
7
+ This might be useful for you main blog roll page to show a paragraph
8
+ from your last 10 posts, each followed by a read more link
9
+
10
+ Install
11
+ ==
12
+
13
+ gem install maruku_snippet
14
+
15
+ Usage
16
+ ==
17
+
18
+ This just addes the to_html_snippet(lines) method to maruku, everything else stays the same.
19
+
20
+ require 'maruku_snippet'
21
+
22
+ doc = MarukuSnippet.new(markdown_string)
23
+ puts doc.to_html_snippet(10)
24
+
25
+ Maruku would be:
26
+
27
+ require 'maruku'
28
+
29
+ doc = Maruku.new(markdown_string)
30
+ puts doc.to_html
31
+
32
+ Markdown Syntax
33
+ ==
34
+
35
+ For syntax see [DaringFireball][].
36
+
37
+ [DaringFireball]: http://daringfireball.net/projects/markdown/syntax
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+
2
+ require 'rspec/core/rake_task'
3
+
4
+ file_list = FileList['spec/*_spec.rb']
5
+
6
+ RSpec::Core::RakeTask.new('spec') do |t|
7
+ t.pattern = file_list
8
+ t.rspec_opts = ["--colour", "--format progress"]
9
+ end
10
+
11
+ desc 'Default: run specs.'
12
+ task :default => 'spec'
@@ -0,0 +1,18 @@
1
+ # encoding: UTF-8
2
+ require 'maruku'
3
+
4
+ module MaRuKuSnippet
5
+ VERSION = '0.0.1'
6
+ end
7
+
8
+ ## ruby 1.9.2+ methods first fall back to 1.8 style
9
+ begin
10
+ require_relative 'maruku_snippet/maruku_snippet_document'
11
+ rescue
12
+ require 'maruku_snippet/maruku_snippet_document'
13
+ end
14
+
15
+ # This is the public interface
16
+ class MarukuSnippet < MaRuKuSnippet::Document;
17
+ end
18
+
@@ -0,0 +1,62 @@
1
+ module MaRuKuSnippet
2
+ class Document
3
+
4
+ def initialize( markdown )
5
+ @markdown = markdown
6
+ end
7
+
8
+ ## TODO or maybe not, we currently cut styling -- == underlining if it is on the line after the cut off length.
9
+ # would you want a snippet ending with a heading though?
10
+
11
+ def to_html_snippet( lines=-1 )
12
+ if lines == -1
13
+ return Maruku.new(@markdown).to_html
14
+ else
15
+
16
+ markdown_a = @markdown.split("\n")
17
+ markdown_temp = (markdown_a[0...lines]).join("\n")
18
+
19
+ ## Is the input text longer than cut off length
20
+ if markdown_a.size > lines
21
+ ## Are we mid table ?
22
+ mid_table = false
23
+ if markdown_a[lines-1].match(/\|/) and markdown_a[lines].match(/\|/)
24
+ mid_table = true
25
+ end
26
+
27
+ ## Looking for markdown elements we can not break (Link targets, tables)
28
+ (markdown_a[lines...(markdown_a.size)]).each_with_index do |text, index|
29
+ ## Make sure keep link targets
30
+ if text.match(/^[ \t ]*\[[\W\w]*\]:[\W\w]*/)
31
+ markdown_temp << "\n" + text
32
+ end
33
+
34
+ if mid_table
35
+ #Still parsing table or have we finished
36
+ if text.match(/\|/)
37
+ markdown_temp << "\n" + text
38
+ else
39
+ mid_table = false
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ return Maruku.new(markdown_temp).to_html
46
+ end
47
+ end
48
+
49
+ ## Delegate to to Maruku via method missing
50
+ def method_missing(method, *args, &block)
51
+ delegate = Maruku.new( @markdown )
52
+ if delegate.respond_to? method
53
+ return delegate.send(method)
54
+ else
55
+ raise NoMethodError
56
+ end
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib")
4
+ require 'maruku_snippet'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'maruku_snippet'
8
+ s.version = MaRuKuSnippet::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Morgan Prior"]
11
+ s.email = ["maruku_snippet@amaras-tech.co.uk"]
12
+ s.homepage = "http://github.com/morganp/maruku_snippet"
13
+ s.summary = %q{Just like Maruku but with snippets }
14
+ s.description = %q{maruku_snippet adds the to_html_snippet(lines) method.
15
+ All existing features of Maruku are delegated to Maruku.}
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('maruku', '>= 0.6.0')
23
+ end
@@ -0,0 +1,25 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe MarukuSnippet do
5
+ it "Parse complete Markdown" do
6
+ basic_md = "line1 \n[line2][] \nline3 \nline4 \nline5 \n[line2]: http://google.co.uk"
7
+ test = MarukuSnippet.new( basic_md )
8
+
9
+ test.to_html.should == %{<p>line1<br /><a href='http://google.co.uk'>line2</a><br />line3<br />line4<br />line5</p>}
10
+
11
+ snippet = test.to_html_snippet(10)
12
+ snippet.should == %{<p>line1<br /><a href='http://google.co.uk'>line2</a><br />line3<br />line4<br />line5</p>}
13
+ end
14
+
15
+ it "Parse limited markdown with out breaking links" do
16
+ basic_md = "line1 \n[line2][] \nline3 \nline4 \nline5 \n[line2]: http://google.co.uk"
17
+ test = MarukuSnippet.new( basic_md )
18
+
19
+ test.to_html.should == %{<p>line1<br /><a href='http://google.co.uk'>line2</a><br />line3<br />line4<br />line5</p>}
20
+
21
+ snippet = test.to_html_snippet(3)
22
+ snippet.should == %{<p>line1<br /><a href='http://google.co.uk'>line2</a><br />line3</p>}
23
+ end
24
+ end
25
+
@@ -0,0 +1,5 @@
1
+
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ require 'rspec'
5
+ require 'maruku_snippet'
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maruku_snippet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Morgan Prior
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: maruku
16
+ requirement: &2153294820 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.6.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2153294820
25
+ description: ! 'maruku_snippet adds the to_html_snippet(lines) method.
26
+
27
+ All existing features of Maruku are delegated to Maruku.'
28
+ email:
29
+ - maruku_snippet@amaras-tech.co.uk
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - .rvmrc
36
+ - Gemfile
37
+ - LICENSE
38
+ - README.md
39
+ - Rakefile
40
+ - lib/maruku_snippet.rb
41
+ - lib/maruku_snippet/maruku_snippet_document.rb
42
+ - maruku_snippet.gemspec
43
+ - spec/maruku_snippet_spec.rb
44
+ - spec/spec_helper.rb
45
+ homepage: http://github.com/morganp/maruku_snippet
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.17
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Just like Maruku but with snippets
69
+ test_files:
70
+ - spec/maruku_snippet_spec.rb
71
+ - spec/spec_helper.rb