middleman-plaintext 0.8.0
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 +7 -0
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +35 -0
- data/Rakefile +1 -0
- data/lib/middleman-plaintext/extension.rb +40 -0
- data/lib/middleman-plaintext/version.rb +5 -0
- data/lib/middleman-plaintext.rb +4 -0
- data/middleman-plaintext.gemspec +22 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e8b489cb329dbdc6de7f164dbe87a5b1a2ad6116
|
4
|
+
data.tar.gz: 2416e0bedfe5afa5ef7bd4357fb9b2e96ed9c443
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e73f75c621490a830ffef49a08bd65df0ca0d53d807339e5996630bbe1c14b186dce7cffb8008fce1a78d21eabf391df7372e816ffb613ba0a269524883b56cc
|
7
|
+
data.tar.gz: 488663d17561d3376b644f7144b6fdc2fc51c1b0ab1bb748d5aa4fd2745cf1013c25f536fb112feefbaf96e16a1de3cd370520de01cf892e2975c17f16765819
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Caius Durling
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# middleman-plaintext
|
2
|
+
|
3
|
+
Generate plaintext versions of resources. Inspired heavily by John Gruber at [daring fireball][], displaying the raw markdown used to generate a post by appending `.text` to the URL. (eg, <http://daringfireball.net/2010/07/improved_regex_for_matching_urls.text>)
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Out of the box the extension expects `layout/layout.text.erb` to be the layout for plaintext rendering of resources, and it also will ignore all resources.
|
8
|
+
|
9
|
+
You'll want to tell it which resources to generate a plaintext version of using the `handle_file` option, which expects a ruby block.
|
10
|
+
|
11
|
+
This basic example, will render all resources with `layout/layout.text.erb`, by putting the following in `config.rb`:
|
12
|
+
|
13
|
+
activate :plaintext do |c|
|
14
|
+
c.handle_file = -> (resource) { true }
|
15
|
+
end
|
16
|
+
|
17
|
+
A slightly more real-world example overrides the template name, and only "plaintexts" HTML files in the post/ directory:
|
18
|
+
|
19
|
+
activate :plaintext do |c|
|
20
|
+
c.layout = "blog_post.text"
|
21
|
+
c.handle_file = lambda do |resource|
|
22
|
+
resource.path.start_with?("posts/") && resource.path.end_with?(".html")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
## Helpful things to know
|
27
|
+
|
28
|
+
* Current resource is `current_page` in the layout as usual
|
29
|
+
* Link to the current page
|
30
|
+
|
31
|
+
URI.join(app.config.site_url, current_page.path.sub("index.text", ""))
|
32
|
+
|
33
|
+
* Render the source file completely raw, without the frontmatter
|
34
|
+
|
35
|
+
Middleman::FileRenderer.new(@app, current_page.file_descriptor[:full_path].to_s).template_data_for_file
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "middleman-plaintext/version"
|
2
|
+
require "middleman-core"
|
3
|
+
|
4
|
+
module Middleman
|
5
|
+
class PlaintextExtension < Extension
|
6
|
+
|
7
|
+
option :layout, "layout.text", "Layout to use for text file"
|
8
|
+
option :handle_file, -> (resource) { false }, "block to decide whether to plaintext a resource"
|
9
|
+
|
10
|
+
# This should run after most other sitemap manipulators so that it
|
11
|
+
# gets a chance to modify any new resources that get added.
|
12
|
+
self.resource_list_manipulator_priority = Float::INFINITY
|
13
|
+
|
14
|
+
# A Sitemap Manipulator
|
15
|
+
def manipulate_resource_list(resources)
|
16
|
+
resources | resources.select(&method(:handled_by_us?)).map(&method(:textify))
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def handled_by_us?(resource)
|
22
|
+
options[:handle_file].call(resource)
|
23
|
+
end
|
24
|
+
|
25
|
+
def textify(resource)
|
26
|
+
to = resource.destination_path.sub("/index.html", "/index.text")
|
27
|
+
source = resource.file_descriptor[:full_path].to_s
|
28
|
+
|
29
|
+
::Middleman::Sitemap::Resource.new(app.sitemap, to, source).tap do |r|
|
30
|
+
r.options.merge!(resource.options.merge(
|
31
|
+
:directory_index => false,
|
32
|
+
:layout => options[:layout]
|
33
|
+
))
|
34
|
+
r.add_metadata resource.metadata
|
35
|
+
r.extend Middleman::Blog::BlogArticle
|
36
|
+
r.blog_controller = app.extensions[:blog]["instance_0"]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "middleman-plaintext/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "middleman-plaintext"
|
7
|
+
s.version = Middleman::Plaintext::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Caius Durling"]
|
10
|
+
s.email = %w(dev@caius.name)
|
11
|
+
s.summary = %{Generate plaintext versions of resources}
|
12
|
+
s.description = %{Generate raw un-rendered versions of selected resources. Shout out to John Gruber for the original idea - eg: http://daringfireball.net/2010/07/improved_regex_for_matching_urls.text}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_runtime_dependency "middleman-core", "~> 4.1"
|
20
|
+
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-plaintext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Caius Durling
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: 'Generate raw un-rendered versions of selected resources. Shout out to
|
42
|
+
John Gruber for the original idea - eg: http://daringfireball.net/2010/07/improved_regex_for_matching_urls.text'
|
43
|
+
email:
|
44
|
+
- dev@caius.name
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/middleman-plaintext.rb
|
55
|
+
- lib/middleman-plaintext/extension.rb
|
56
|
+
- lib/middleman-plaintext/version.rb
|
57
|
+
- middleman-plaintext.gemspec
|
58
|
+
homepage:
|
59
|
+
licenses: []
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.6.4
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Generate plaintext versions of resources
|
81
|
+
test_files: []
|