jekyll-itafroma-collapse_newlines 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/jekyll/itafroma/collapse_newlines.rb +57 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a97cae44a46339a3153a59678973a11693ced926
|
4
|
+
data.tar.gz: 8dfef2392a3fb39e82367cf51e5c259c8fbe1c40
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a6355586df362dc83b1bf629c8ed8666dfa5bdbf89b80cef78b435c2b8643bbeee362f9b47a2963a140635334aec63a741911df2e9ef05d132c86d23d5d074dc
|
7
|
+
data.tar.gz: 964c21433b1a1a7354e7068d8550aa112fd76b8a194e21d7144ee65e016e918837558a68f5b4a6b995cc7a8151c82de52453bd431d8ea03a722274ee6bf66264
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#
|
2
|
+
# Strips extraneous whitespace from rendered files.
|
3
|
+
#
|
4
|
+
# I modified kerotaa's original plugin to strip newlines from non HTML files
|
5
|
+
# and to make a few style changes.
|
6
|
+
#
|
7
|
+
# Derivative work:
|
8
|
+
# Author:: Mark Trapp
|
9
|
+
# Copyright:: Copyright (c) 2013 Mark Trapp
|
10
|
+
# License:: MIT
|
11
|
+
#
|
12
|
+
# Original work:
|
13
|
+
# Author:: kerotaa
|
14
|
+
# Copyright:: Copyright (c) 2012 kerotaa
|
15
|
+
# License:: MIT
|
16
|
+
# URL:: https://gist.github.com/kerotaa/5788650
|
17
|
+
#
|
18
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
19
|
+
# of this software and associated documentation files (the "Software"), to deal
|
20
|
+
# in the Software without restriction, including without limitation the rights
|
21
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
22
|
+
# copies of the Software, and to permit persons to whom the Software is
|
23
|
+
# furnished to do so, subject to the following conditions:
|
24
|
+
#
|
25
|
+
# The above copyright notice and this permission notice shall be included in
|
26
|
+
# all copies or substantial portions of the Software.
|
27
|
+
|
28
|
+
module Jekyll
|
29
|
+
module Convertible
|
30
|
+
def write(dest)
|
31
|
+
path = destination(dest)
|
32
|
+
FileUtils.mkdir_p(File.dirname(path))
|
33
|
+
output.strip!
|
34
|
+
|
35
|
+
newline_regexp = /^[\s\t]*(\r\n|\r|\n)/
|
36
|
+
|
37
|
+
if File.extname(path).downcase.eql? '.html'
|
38
|
+
# If the file is HTML, newlines within <pre> elements should not be
|
39
|
+
# collapsed.
|
40
|
+
pre_regexp = /<\/?pre[^>]*>/i
|
41
|
+
pre_list = output.scan(pre_regexp)
|
42
|
+
blocks = output.split(pre_regexp)
|
43
|
+
|
44
|
+
collapsed_blocks = []
|
45
|
+
blocks.each_with_index do |block, i|
|
46
|
+
collapsed_blocks << (i.odd? ? block : block.gsub(newline_regexp, ''))
|
47
|
+
collapsed_blocks << pre_list[i] if pre_list.size > i
|
48
|
+
end
|
49
|
+
self.output = collapsed_blocks.join('')
|
50
|
+
else
|
51
|
+
self.output = output.gsub(newline_regexp, '')
|
52
|
+
end
|
53
|
+
|
54
|
+
File.open(path, 'w') { |f| f.write(output) }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-itafroma-collapse_newlines
|
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 strip extraneous whitespace.
|
14
|
+
email: mark@marktrapp.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/jekyll/itafroma/collapse_newlines.rb
|
20
|
+
homepage: http://marktrapp.com/projects/jekyll-collapse-newlines
|
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 strip extraneous whitespace.
|
44
|
+
test_files: []
|