jekyll-itafroma-indent_filter 0.1.0

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: d335b432ea2f32be1895cb24ace15670bdcfd720
4
+ data.tar.gz: 5ce165c126d867534b2caf7ab9647247aca96d71
5
+ SHA512:
6
+ metadata.gz: 3c040c43147bf213fc20632f6b873a5be26ffffd55d9bb2b658db9ce4d98ba7282ebd758e32a162f61f3b4845e695da0df1c65bc9a62ec0630517df5be661d17
7
+ data.tar.gz: 2c961f4a8c310090514b508a834cbf877663c022e8a3b9428fda528ce8594cfe71796441dafea5083e0d3371a9801b351513b651a25ed7f7993a53d8e4cc2aca
@@ -0,0 +1,45 @@
1
+ #
2
+ # Provides a Liquid filter for indenting content.
3
+ #
4
+ # Indents the contents of a tag by a specified number of spaces. Accounts for
5
+ # <pre> elements in HTML, which should not have their indentation altered.
6
+ #
7
+ # Author:: Mark Trapp
8
+ # Copyright: Copyright (c) 2013 Mark Trapp
9
+ # License:: MIT
10
+ # Acknowledgements::
11
+ # - Inspired by the example provided by Mike Fulcher:
12
+ # http://drawingablank.me/blog/indentation-for-injected-jekyll-content.html
13
+ # - <pre> element handling inspired by kerotaa's newline collapsing plugin:
14
+ # https://gist.github.com/kerotaa/5788650
15
+ # See also collapse_newlines.rb
16
+
17
+ module Jekyll
18
+ module Itafroma
19
+ module IndentFilter
20
+ def indent(content, indent = 0)
21
+ output = []
22
+
23
+ pre_regexp = /<\/?pre[^>]*>/i
24
+ pre_list = content.scan(pre_regexp)
25
+ blocks = content.split(pre_regexp)
26
+
27
+ blocks.each_with_index do |block, i|
28
+ if i.odd?
29
+ output << block
30
+ else
31
+ # The first line should already be indented.
32
+ output << block.lines.first
33
+ block.lines.to_a[1..-1].each do |line|
34
+ output << (' ' * indent.to_i) + line
35
+ end
36
+ end
37
+ output << pre_list[i] if pre_list.size > i
38
+ end
39
+ output.join('')
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ Liquid::Template.register_filter(Jekyll::Itafroma::IndentFilter)
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-itafroma-indent_filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Trapp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Jekyll plugin to provide an indentation filter.
14
+ email: mark@marktrapp.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/jekyll/itafroma/indent_filter.rb
20
+ homepage: http://marktrapp.com/projects/jekyll-indent-filter
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.0.6
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Jekyll plugin to provide an indentation filter.
44
+ test_files: []