jekyll-figure 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: 372f820a218473fad59e88084c452abe66156957
4
+ data.tar.gz: daa8dffcc22670969f62bcdd72b35747b3874d44
5
+ SHA512:
6
+ metadata.gz: 83f69bb1bca5caa7e5011e3141df937f6064b42702d497d40a7c500be6a46b0436be3a2838d88c48676263e98c4f48628c66827d8bf31957203837adc2e2fd3f
7
+ data.tar.gz: 044b9339c6d4098d8c6cede43cd1664204d515107053f1453ce60cde73874bde8f493e38630fb5640059c8b479d98d80a9b029499f9bfd59871b2c64714bf72b
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ spec/dest
4
+ .bundle
5
+ .jekyll-metadata
6
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ if ENV["JEKYLL_VERSION"]
5
+ gem "jekyll", "~> #{ENV["JEKYLL_VERSION"]}"
6
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Paul Robert Lloyd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # jekyll-figure
2
+
3
+ A liquid tag for Jekyll that generates `<figure>` elements.
4
+
5
+ [![Gem Version](https://img.shields.io/gem/v/jekyll-figure.svg)](https://rubygems.org/gems/jekyll-figure)
6
+
7
+ ## Installation
8
+
9
+ 1. Add `gem 'jekyll-figure'` to your site’s Gemfile and run `bundle`
10
+ 2. Add the following to your site’s `_config.yml`:
11
+
12
+ ```yml
13
+ gems:
14
+ - jekyll-figure
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ This plugin provides a liquid tag that enables you to generate a `<figure>` element. It takes optional `caption` and `class` parameters.
20
+
21
+ ```
22
+ {% figure [caption:"Caption (markdown)"] [class:"class1 class2"] %}
23
+ Figure content (markdown)
24
+ {% endfigure %}
25
+ ```
26
+
27
+ ### Examples
28
+
29
+ In simplest usage:
30
+
31
+ ```
32
+ {% figure %}
33
+ Content
34
+ {% endfigure %}
35
+ ```
36
+
37
+ ```html
38
+ <figure>
39
+ <p>Content</p>
40
+ </figure>
41
+ ```
42
+
43
+ If a figure contains an image (or multiple images), the surrounding `<p>` will be stripped:
44
+
45
+ ```
46
+ {% figure %}
47
+ ![Image](/path/to/image.jpg)
48
+ {% endfigure %}
49
+ ```
50
+
51
+ ```html
52
+ <figure>
53
+ <img src="/path/to/image.jpg" alt="Image" />
54
+ </figure>
55
+ ```
56
+
57
+ You can provide a caption. Any markdown will be rendered:
58
+
59
+ ```
60
+ {% figure caption:"*Markdown* caption" %}
61
+ Content
62
+ {% endfigure %}
63
+ ```
64
+
65
+ ```html
66
+ <figure>
67
+ <p>Content</p>
68
+ <figcaption><em>Markdown</em> caption</figcaption>
69
+ </figure>
70
+ ```
71
+
72
+ You can also provide a class name(es) for CSS styling:
73
+
74
+ ```
75
+ {% figure caption:"A caption" | class:"classname" %}
76
+ Content
77
+ {% endfigure %}
78
+ ```
79
+
80
+ ```html
81
+ <figure class="classname">
82
+ <p>Content</p>
83
+ <figcaption>A caption</figcaption>
84
+ </figure>
85
+ ```
86
+
87
+ Finally, the `caption` parameter will accept liquid ouput markup:
88
+
89
+ ```
90
+ {% figure caption:"{{ page.title }}" %}
91
+ Content
92
+ {% endfigure %}
93
+ ```
94
+
95
+ ```html
96
+ <figure>
97
+ <p>Content</p>
98
+ <figcaption>The title of my post</figcaption>
99
+ </figure>
100
+ ```
101
+
102
+ ## Testing
103
+
104
+ 1. `script/bootstrap`
105
+ 2. `script/cibuild`
106
+
107
+ ## Contributing
108
+
109
+ 1. Fork the project
110
+ 2. Create a descriptively named feature branch
111
+ 3. Add your feature
112
+ 4. Submit a pull request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jekyll/figure/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll-figure"
8
+ spec.version = Jekyll::Figure::VERSION
9
+ spec.summary = "Jekyll plugin that generates <figure> elements."
10
+ spec.description = "A liquid tag for Jekyll that generates <figure> elements."
11
+ spec.authors = ["Paul Robert Lloyd"]
12
+ spec.email = "me+rubygems@paulrobertlloyd.com"
13
+ spec.files = Dir.glob("lib/**/*.rb")
14
+ spec.homepage = "https://github.com/paulrobertlloyd/jekyll-figure"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "jekyll", [">= 2.0", "< 4.0"]
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency 'rake', '~> 0'
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ end
@@ -0,0 +1,57 @@
1
+ module Jekyll
2
+ module Figure
3
+
4
+ class FigureTag < Liquid::Block
5
+ def initialize(tag_name, markup, tokens)
6
+ @markup = markup
7
+ super
8
+ end
9
+
10
+ def render(context)
11
+ # Gather settings
12
+ site = context.registers[:site]
13
+ converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
14
+
15
+ # Render any liquid variables
16
+ markup = Liquid::Template.parse(@markup).render(context)
17
+
18
+ # Extract tag attributes
19
+ attributes = {}
20
+ markup.scan(Liquid::TagAttributes) do |key, value|
21
+ attributes[key] = value
22
+ end
23
+
24
+ @caption = attributes['caption']
25
+ @class = attributes['class']
26
+
27
+ # Caption: convert markdown and remove paragraphs
28
+ unless @caption.nil?
29
+ figure_caption = @caption.gsub!(/\A"|"\Z/, '')
30
+ figure_caption = converter.convert(figure_caption).gsub(/<\/?p[^>]*>/, '').chomp
31
+ figure_caption = " <figcaption>#{figure_caption}</figcaption>\n"
32
+ end
33
+
34
+ # Class name(s)
35
+ unless @class.nil?
36
+ figure_class = @class.gsub!(/\A"|"\Z/, '')
37
+ figure_class = " class\=\"#{figure_class}\""
38
+ end
39
+
40
+ # Content: convert markdown and remove paragraphs containing images
41
+ figure_main = converter.convert(super(context)).gsub(/^<p>\s*((<img[^<]+?)+)\s*<\/p>(.*)/, '\\1').gsub!(/[\n]+/, "\n ");
42
+
43
+ # Used to escape markdown parsing rendering
44
+ markdown_escape = "\ "
45
+
46
+ # Render <figure>
47
+ figure_tag = "<figure#{figure_class}>"
48
+ figure_tag += "#{figure_main}\n"
49
+ figure_tag += "#{figure_caption}"
50
+ figure_tag += "</figure>"
51
+ end
52
+ end
53
+
54
+ end
55
+ end
56
+
57
+ Liquid::Template.register_tag('figure', Jekyll::Figure::FigureTag)
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module Figure
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/script/bootstrap ADDED
@@ -0,0 +1,3 @@
1
+ #! /bin/bash
2
+
3
+ bundle install
data/script/cibuild ADDED
@@ -0,0 +1,3 @@
1
+ #! /bin/bash
2
+
3
+ bundle exec rspec
data/script/console ADDED
@@ -0,0 +1,34 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ def relative_to_root(path)
4
+ File.expand_path(path, File.dirname(File.dirname(__FILE__)))
5
+ end
6
+
7
+ require 'jekyll'
8
+ require relative_to_root('lib/jekyll-figure.rb')
9
+ require 'pry-debugger'
10
+
11
+ SOURCE_DIR = relative_to_root('spec/fixtures')
12
+ DEST_DIR = relative_to_root('spec/dest')
13
+
14
+ def source_dir(*files)
15
+ File.join(SOURCE_DIR, *files)
16
+ end
17
+
18
+ def dest_dir(*files)
19
+ File.join(DEST_DIR, *files)
20
+ end
21
+
22
+ def config(overrides = {})
23
+ Jekyll.configuration({
24
+ "source" => source_dir,
25
+ "destination" => dest_dir,
26
+ "url" => "http://example.org"
27
+ }).merge(overrides)
28
+ end
29
+
30
+ def site(configuration = config)
31
+ Jekyll::Site.new(configuration)
32
+ end
33
+
34
+ binding.pry
data/script/release ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ # Tag and push a release.
3
+
4
+ set -e
5
+
6
+ script/cibuild
7
+ bundle exec rake release
@@ -0,0 +1,9 @@
1
+ timezone: UTC
2
+
3
+ defaults:
4
+ -
5
+ scope:
6
+ path: ""
7
+ type: page
8
+ values:
9
+ layout: some_default
@@ -0,0 +1,25 @@
1
+ ---
2
+ ---
3
+ {% figure %}
4
+ Content
5
+ {% endfigure %}
6
+
7
+ {% figure %}
8
+ ![Image](#)
9
+ {% endfigure %}
10
+
11
+ {% figure caption:"A caption" %}
12
+ Content
13
+ {% endfigure %}
14
+
15
+ {% figure caption:"A caption" | class:"red" %}
16
+ Content
17
+ {% endfigure %}
18
+
19
+ {% figure caption:"*Markdown* content" %}
20
+ **Markdown** content
21
+ {% endfigure %}
22
+
23
+ {% figure caption:"{{ page.test }}" %}
24
+ Content
25
+ {% endfigure %}
@@ -0,0 +1,5 @@
1
+ ---
2
+ test:
3
+ - Page data
4
+ ---
5
+ Each test should be an item in `page.test`
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe(Jekyll) do
4
+ let(:overrides) do
5
+ {
6
+ "source" => source_dir,
7
+ "destination" => dest_dir,
8
+ "url" => "http://example.org",
9
+ }
10
+ end
11
+ let(:config) do
12
+ Jekyll.configuration(overrides)
13
+ end
14
+ let(:site) { Jekyll::Site.new(config) }
15
+ let(:contents) { File.read(dest_dir("index.html")) }
16
+ before(:each) do
17
+ site.process
18
+ end
19
+
20
+ it "creates a figure element" do
21
+ expect(contents).to match /<figure>\n <p>Content<\/p>\n \n<\/figure>/
22
+ end
23
+
24
+ it "creates a figure element with image content" do
25
+ expect(contents).to match /<figure>\n <img src="#" alt="Image" \/>\n \n<\/figure>/
26
+ end
27
+
28
+ it "creates a figure element with caption" do
29
+ expect(contents).to match /<figure>\n <p>Content<\/p>\n \n <figcaption>A caption<\/figcaption>\n<\/figure>/
30
+ end
31
+
32
+ it "creates a figure element with caption and class name" do
33
+ expect(contents).to match /<figure>\n <p><strong>Markdown<\/strong> content<\/p>\n \n <figcaption><em>Markdown<\/em> content<\/figcaption>\n<\/figure>/
34
+ end
35
+
36
+ it "creates a figure element with liquid variable for caption" do
37
+ expect(contents).to match /<figure>\n <p>Content<\/p>\n \n <figcaption>Page data<\/figcaption>\n<\/figure>/
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ require 'jekyll'
2
+ require File.expand_path('../lib/jekyll/figure', File.dirname(__FILE__))
3
+
4
+ Jekyll.logger.log_level = :error
5
+
6
+ RSpec.configure do |config|
7
+ config.run_all_when_everything_filtered = true
8
+ config.filter_run :focus
9
+ config.order = 'random'
10
+
11
+ SOURCE_DIR = File.expand_path("../fixtures", __FILE__)
12
+ DEST_DIR = File.expand_path("../dest", __FILE__)
13
+
14
+ def source_dir(*files)
15
+ File.join(SOURCE_DIR, *files)
16
+ end
17
+
18
+ def dest_dir(*files)
19
+ File.join(DEST_DIR, *files)
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-figure
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Robert Lloyd
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4.0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.6'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.6'
75
+ description: A liquid tag for Jekyll that generates <figure> elements.
76
+ email: me+rubygems@paulrobertlloyd.com
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - ".gitignore"
82
+ - Gemfile
83
+ - LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - jekyll-figure.gemspec
87
+ - lib/jekyll/figure.rb
88
+ - lib/jekyll/figure/version.rb
89
+ - script/bootstrap
90
+ - script/cibuild
91
+ - script/console
92
+ - script/release
93
+ - spec/fixtures/_config.yml
94
+ - spec/fixtures/_layouts/some_default.html
95
+ - spec/fixtures/index.html
96
+ - spec/jekyll-figure_spec.rb
97
+ - spec/spec_helper.rb
98
+ homepage: https://github.com/paulrobertlloyd/jekyll-figure
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.6
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Jekyll plugin that generates <figure> elements.
122
+ test_files:
123
+ - spec/fixtures/_config.yml
124
+ - spec/fixtures/_layouts/some_default.html
125
+ - spec/fixtures/index.html
126
+ - spec/jekyll-figure_spec.rb
127
+ - spec/spec_helper.rb