jekyll-snippets 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b05ebbc313269c2d81cf11d180bf054e6a85580
4
+ data.tar.gz: 09781e3cd595487c5c64396b5708fef48f24ee98
5
+ SHA512:
6
+ metadata.gz: a099f7cf2076c046e0e7390795f9c4bb88e75ea6af88b4222152078e1129b64b5e97e4f3d4c1eac53f34f18066a94196c382393504df5643057afd2a890532c6
7
+ data.tar.gz: a82c90c4f7a102df6a4b6a6f4ee933fcd5d1155a3f38a653e6d058e7ebe2008f96436ace2dd2ff1b97f99755b6f0ce2c7c4175a364b84b82cb3bb93c8e7f579b
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .ruby-*
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm: 2.2.1
3
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,102 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jekyll-snippets (0.0.0)
5
+ jekyll (>= 2.5)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ blankslate (2.1.2.4)
11
+ celluloid (0.16.0)
12
+ timers (~> 4.0.0)
13
+ classifier-reborn (2.0.3)
14
+ fast-stemmer (~> 1.0)
15
+ coderay (1.1.0)
16
+ coffee-script (2.4.1)
17
+ coffee-script-source
18
+ execjs
19
+ coffee-script-source (1.9.1.1)
20
+ colorator (0.1)
21
+ diff-lcs (1.2.5)
22
+ execjs (2.6.0)
23
+ fast-stemmer (1.0.2)
24
+ ffi (1.9.10)
25
+ hitimes (1.2.2)
26
+ jekyll (2.5.3)
27
+ classifier-reborn (~> 2.0)
28
+ colorator (~> 0.1)
29
+ jekyll-coffeescript (~> 1.0)
30
+ jekyll-gist (~> 1.0)
31
+ jekyll-paginate (~> 1.0)
32
+ jekyll-sass-converter (~> 1.0)
33
+ jekyll-watch (~> 1.1)
34
+ kramdown (~> 1.3)
35
+ liquid (~> 2.6.1)
36
+ mercenary (~> 0.3.3)
37
+ pygments.rb (~> 0.6.0)
38
+ redcarpet (~> 3.1)
39
+ safe_yaml (~> 1.0)
40
+ toml (~> 0.1.0)
41
+ jekyll-coffeescript (1.0.1)
42
+ coffee-script (~> 2.2)
43
+ jekyll-gist (1.3.4)
44
+ jekyll-paginate (1.1.0)
45
+ jekyll-sass-converter (1.3.0)
46
+ sass (~> 3.2)
47
+ jekyll-watch (1.2.1)
48
+ listen (~> 2.7)
49
+ kramdown (1.8.0)
50
+ liquid (2.6.3)
51
+ listen (2.10.1)
52
+ celluloid (~> 0.16.0)
53
+ rb-fsevent (>= 0.9.3)
54
+ rb-inotify (>= 0.9)
55
+ mercenary (0.3.5)
56
+ method_source (0.8.2)
57
+ parslet (1.5.0)
58
+ blankslate (~> 2.0)
59
+ posix-spawn (0.3.11)
60
+ pry (0.10.1)
61
+ coderay (~> 1.1.0)
62
+ method_source (~> 0.8.1)
63
+ slop (~> 3.4)
64
+ pygments.rb (0.6.3)
65
+ posix-spawn (~> 0.3.6)
66
+ yajl-ruby (~> 1.2.0)
67
+ rake (10.4.2)
68
+ rb-fsevent (0.9.5)
69
+ rb-inotify (0.9.5)
70
+ ffi (>= 0.5.0)
71
+ redcarpet (3.3.2)
72
+ rspec (3.3.0)
73
+ rspec-core (~> 3.3.0)
74
+ rspec-expectations (~> 3.3.0)
75
+ rspec-mocks (~> 3.3.0)
76
+ rspec-core (3.3.2)
77
+ rspec-support (~> 3.3.0)
78
+ rspec-expectations (3.3.1)
79
+ diff-lcs (>= 1.2.0, < 2.0)
80
+ rspec-support (~> 3.3.0)
81
+ rspec-mocks (3.3.2)
82
+ diff-lcs (>= 1.2.0, < 2.0)
83
+ rspec-support (~> 3.3.0)
84
+ rspec-support (3.3.0)
85
+ safe_yaml (1.0.4)
86
+ sass (3.4.18)
87
+ slop (3.6.0)
88
+ timers (4.0.1)
89
+ hitimes
90
+ toml (0.1.2)
91
+ parslet (~> 1.5.0)
92
+ yajl-ruby (1.2.1)
93
+
94
+ PLATFORMS
95
+ ruby
96
+
97
+ DEPENDENCIES
98
+ bundler (~> 1.3)
99
+ jekyll-snippets!
100
+ pry
101
+ rake
102
+ rspec
data/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # Jekyll-Snippets
2
+
3
+ ![Build Status](https://travis-ci.org/yez/jekyll-snippets.svg?branch=master)
4
+
5
+ Post archive page plugin for Jekyll powered blogs
6
+
7
+ ### Installation
8
+
9
+ ### Configuration
10
+
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__)) unless $LOAD_PATH.include?(File.dirname(__FILE__))
2
+
3
+ require './version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'jekyll-snippets'
7
+ s.version = Jekyll::JekyllSnippets::VERSION
8
+ s.summary = %q{Generates archive snippets for a jekyll site}
9
+ s.description = %q{This plugin will generate an html file that can be accessible by default at /archives/index.html for a jekyll static blog. Additional CSS will be required to acheive the desired look and feel.}
10
+ s.authors = ['Jake Yesbeck']
11
+ s.email = 'yesbeckjs@gmail.com'
12
+ s.homepage = %q{https://github.com/yez/jekyll-snippets}
13
+ s.license = 'MIT'
14
+
15
+ s.require_paths = ['lib']
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = s.files.grep(/^spec\//)
18
+
19
+ s.required_ruby_version = '>= 2.0.0'
20
+ s.add_dependency 'jekyll', '>= 2.5'
21
+
22
+ s.add_development_dependency 'bundler', '~> 1.3'
23
+ s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'rspec'
25
+ s.add_development_dependency 'pry'
26
+ end
@@ -0,0 +1,11 @@
1
+ require 'jekyll'
2
+ require './lib/config'
3
+ require './lib/formatter'
4
+ require './lib/renderer'
5
+ require './lib/snippet'
6
+ require './lib/snippet_generator'
7
+
8
+ module Jekyll
9
+ module JekyllSnippets
10
+ end
11
+ end
data/lib/config.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Jekyll
2
+ module JekyllSnippets
3
+ class Config
4
+ attr_accessor :output_dir, :output_file
5
+ end
6
+
7
+ def self.config(&config_blok)
8
+ @config ||= Config.new
9
+ end
10
+
11
+ def self.configure
12
+ yield config
13
+ end
14
+ end
15
+ end
data/lib/formatter.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'jekyll'
2
+
3
+ module Jekyll
4
+ module JekyllSnippets
5
+ class Formatter
6
+ include Jekyll::Filters
7
+ include Liquid::StandardFilters
8
+ end
9
+ end
10
+ end
data/lib/renderer.rb ADDED
@@ -0,0 +1,22 @@
1
+ module Jekyll
2
+ module JekyllSnippets
3
+ class Renderer
4
+ attr_reader :snippets
5
+
6
+ def initialize(snippets)
7
+ @snippets = snippets
8
+ end
9
+
10
+ def render(output_destination)
11
+ template = Liquid::Template.parse(File.read(template_file))
12
+ template.render({ 'snippets' => @snippets })
13
+ end
14
+
15
+ private
16
+
17
+ def template_file
18
+ File.expand_path('../../views/index.html.liquid', __FILE__)
19
+ end
20
+ end
21
+ end
22
+ end
data/lib/snippet.rb ADDED
@@ -0,0 +1,34 @@
1
+ module Jekyll
2
+ module JekyllSnippets
3
+ class Snippet
4
+ attr_reader :date, :content, :url
5
+
6
+ def initialize(post, formatter)
7
+ @post = post
8
+ @formatter = formatter
9
+
10
+ @date = formatted_date
11
+ @content = truncated_content
12
+ @url = post.url
13
+ end
14
+
15
+ def render
16
+ template = Liquid::Template.parse(File.read(partial))
17
+ template.render({ 'date' => date, 'content' => content, 'url' => url })
18
+ end
19
+
20
+ def truncated_content
21
+ stripped = @formatter.strip_html(@post.content)
22
+ @formatter.truncate(stripped, 200, '...')
23
+ end
24
+
25
+ def formatted_date
26
+ @formatter.date_to_string(@post.date)
27
+ end
28
+
29
+ def partial
30
+ File.expand_path('snippet.html.liquid', File.dirname(__FILE__) + '/../views')
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,46 @@
1
+ require_relative './snippet'
2
+ require_relative './formatter'
3
+ require_relative './renderer'
4
+
5
+ module Jekyll
6
+ module JekyllSnippets
7
+ class SnippetGenerator < Jekyll::Generator
8
+ attr_reader :site
9
+
10
+ def generate(site)
11
+ @site = site
12
+
13
+ make_dir
14
+
15
+ renderer = JekyllSnippets::Renderer.new(snippets)
16
+ renderer.render(output_destination)
17
+ end
18
+
19
+ private
20
+
21
+ def snippets
22
+ @site.posts.map do |post|
23
+ Snippet.new(post, Formatter.new).render
24
+ end
25
+ end
26
+
27
+ def output_destination
28
+ "#{ output_dir }/#{ output_file }"
29
+ end
30
+
31
+ def make_dir
32
+ Dir.mkdir(output_dir) unless Dir.exist?(output_dir)
33
+ end
34
+
35
+ def output_file
36
+ JekyllSnippets.config.output_file ||
37
+ 'index.html'
38
+ end
39
+
40
+ def output_dir
41
+ JekyllSnippets.config.output_dir ||
42
+ site.in_source_dir('/archives/')
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../spec_helper'
2
+
3
+ module Jekyll
4
+ module JekyllSnippets
5
+ describe Formatter do
6
+ it 'includes jekyll filters' do
7
+ expect(described_class.ancestors).to include(Jekyll::Filters)
8
+ end
9
+
10
+ it 'includes liquid standard filters' do
11
+ expect(described_class.ancestors).to include(Liquid::StandardFilters)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ require_relative '../spec_helper'
2
+ module Jekyll
3
+ module JekyllSnippets
4
+ describe Renderer do
5
+ describe '#initialize' do
6
+ it 'sets the instance variable @snippets' do
7
+ instance = described_class.new(anything)
8
+ expect(instance.instance_variable_get(:@snippets)).to_not be_nil
9
+ end
10
+
11
+ it 'responds to snippets' do
12
+ expect(described_class.new(anything)).to respond_to(:snippets)
13
+ end
14
+ end
15
+
16
+ describe '#render' do
17
+ let(:formatter) { Formatter.new }
18
+ let(:post) { TestPost.new }
19
+ let(:snippets) { 3.times.map { Snippet.new(post, formatter) } }
20
+
21
+ subject { described_class.new(snippets) }
22
+
23
+ it 'loads the index file and renders it' do
24
+ expect(Liquid::Template).to receive(:parse).with(File.read(File.expand_path('../../../views/index.html.liquid', __FILE__))).and_call_original
25
+ subject.render('test_file')
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ require_relative '../spec_helper'
2
+
3
+ module Jekyll
4
+ module JekyllSnippets
5
+ describe SnippetGenerator do
6
+ describe '#generate' do
7
+ subject { described_class.new }
8
+
9
+ before do
10
+ allow(subject).to receive(:snippets) { [] }
11
+ allow(subject).to receive(:make_dir)
12
+ allow(subject).to receive(:output_dir) { '' }
13
+ allow_any_instance_of(JekyllSnippets::Renderer).to receive(:render)
14
+ end
15
+
16
+ it 'sets the site instance variable' do
17
+ subject.generate(anything)
18
+ expect(subject.instance_variable_get(:@site)).to_not be_nil
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,77 @@
1
+ require_relative '../spec_helper'
2
+
3
+ module Jekyll
4
+ module JekyllSnippets
5
+ describe Snippet do
6
+ post = Struct.new('Post', :date_to_string)
7
+
8
+ let(:formatter) { Formatter.new }
9
+
10
+ subject { described_class.new(post, formatter) }
11
+
12
+ before do
13
+ allow(formatter).to receive(:date_to_string)
14
+ allow(post).to receive(:content)
15
+ allow(post).to receive(:url)
16
+ end
17
+
18
+ describe '#initialize' do
19
+ context 'instance variables' do
20
+ before do
21
+ allow_any_instance_of(described_class).to receive(:formatted_date) { anything }
22
+ allow_any_instance_of(described_class).to receive(:truncated_content) { anything }
23
+ allow(post).to receive(:url) { anything }
24
+ end
25
+
26
+ it 'sets the proper instance variables' do
27
+ expect(subject.instance_variable_get(:@date)).to_not be_nil
28
+ expect(subject.instance_variable_get(:@content)).to_not be_nil
29
+ expect(subject.instance_variable_get(:@url)).to_not be_nil
30
+ end
31
+ end
32
+
33
+ context 'methods' do
34
+ it 'calls the proper methods' do
35
+ expect_any_instance_of(described_class).to receive(:formatted_date)
36
+ expect_any_instance_of(described_class).to receive(:truncated_content)
37
+ expect(post).to receive(:url)
38
+
39
+ subject
40
+ end
41
+ end
42
+ end
43
+
44
+ describe '!#truncated_content' do
45
+ let(:content) { 'this is some <b>content</b>' }
46
+ let(:content_without_html) { 'this is some content' }
47
+
48
+ before do
49
+ allow_any_instance_of(described_class).to receive(:formatted_date) { anything }
50
+ allow(post).to receive(:url) { anything }
51
+ allow(post).to receive(:content) { content }
52
+ end
53
+
54
+ it 'strips html and truncates' do
55
+ expect(formatter).to receive(:strip_html).with(content) { content_without_html }
56
+ expect(formatter).to receive(:truncate).with(content_without_html, 200, '...')
57
+ subject
58
+ end
59
+ end
60
+
61
+ describe '!#partial' do
62
+ before do
63
+ allow(post).to receive(:date)
64
+ end
65
+
66
+ it 'renders the correct partial' do
67
+ partial = File.expand_path('snippet.html.liquid', File.dirname(__FILE__) + '../../../views')
68
+ expect(subject.send(:partial)).to eq(partial)
69
+ end
70
+
71
+ it 'the file exists' do
72
+ expect(File.exists?(subject.send(:partial))).to eq(true)
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,12 @@
1
+ require 'pry'
2
+ require_relative '../jekyll-snippets'
3
+
4
+ class TestPost
5
+ def url; end
6
+
7
+ def content; end
8
+
9
+ def date
10
+ Time.now
11
+ end
12
+ end
data/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module JekyllSnippets
3
+ VERSION = '0.0.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ <div class='snippets-container'>
2
+ {% for snippet in snippets %}
3
+ {% include 'snippet' url=snippet.url date=snippet.date content=snippet.content %}
4
+ {% endfor %}
5
+ </div>
@@ -0,0 +1,6 @@
1
+ <div class='snippet'>
2
+ <a href="{{ url }}" class='link'>
3
+ <span class='title'>{{ title }} - {{ date }}</span>
4
+ <div class='content'>{{ content }}</div>
5
+ </a>
6
+ </div>
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-snippets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jake Yesbeck
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-01 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.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This plugin will generate an html file that can be accessible by default
84
+ at /archives/index.html for a jekyll static blog. Additional CSS will be required
85
+ to acheive the desired look and feel.
86
+ email: yesbeckjs@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - README.md
96
+ - jekyll-snippets.gemspec
97
+ - jekyll-snippets.rb
98
+ - lib/config.rb
99
+ - lib/formatter.rb
100
+ - lib/renderer.rb
101
+ - lib/snippet.rb
102
+ - lib/snippet_generator.rb
103
+ - spec/lib/formatter_spec.rb
104
+ - spec/lib/renderer_spec.rb
105
+ - spec/lib/snippet_generator_spec.rb
106
+ - spec/lib/snippet_spec.rb
107
+ - spec/spec_helper.rb
108
+ - version.rb
109
+ - views/index.html.liquid
110
+ - views/snippet.html.liquid
111
+ homepage: https://github.com/yez/jekyll-snippets
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: 2.0.0
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.4.6
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Generates archive snippets for a jekyll site
135
+ test_files:
136
+ - spec/lib/formatter_spec.rb
137
+ - spec/lib/renderer_spec.rb
138
+ - spec/lib/snippet_generator_spec.rb
139
+ - spec/lib/snippet_spec.rb
140
+ - spec/spec_helper.rb