distorted-jekyll 0.5.7 → 0.6.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.
@@ -1,54 +0,0 @@
1
- require 'set'
2
-
3
- require 'distorted-jekyll/static/lastresort'
4
-
5
- module Jekyll
6
- module DistorteD
7
- module Molecule
8
- module LastResort
9
-
10
- MEDIA_TYPE = 'lastresort'.freeze
11
-
12
- # HACK HACK HACK
13
- # Image Maps are a '90s Web relic, but I'm using this
14
- # MIME::Type here to represent the generic fallback state.
15
- # The MIME::Types library doesn't let me register custom
16
- # types without shipping an entire custom type database,
17
- # so I'm just going to use this since it will never
18
- # be detected for a real file, and if it does then it will
19
- # get an <img> tag anyway :)
20
- MIME_TYPES = MIME::Types['application/x-imagemap'].to_set
21
-
22
- ATTRS = Set[:alt, :title, :href, :caption]
23
- ATTRS_DEFAULT = {}
24
- ATTRS_VALUES = {}
25
-
26
- def render_to_output_buffer(context, output)
27
- super
28
- begin
29
- output << parse_template.render({
30
- 'name' => @name,
31
- 'basename' => File.basename(@name, '.*'),
32
- 'path' => @url,
33
- 'alt' => attr_value(:alt),
34
- 'title' => attr_value(:title),
35
- 'href' => attr_value(:href),
36
- 'caption' => attr_value(:caption),
37
- })
38
- rescue Liquid::SyntaxError => l
39
- unless Jekyll.env == 'production'.freeze
40
- output << parse_template(name: 'error_code'.freeze).render({
41
- 'message' => l.message,
42
- })
43
- end
44
- end
45
- output
46
- end
47
-
48
- def static_file(*args)
49
- Jekyll::DistorteD::Static::LastResort.new(*args)
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,42 +0,0 @@
1
- require 'fileutils'
2
- require 'set'
3
-
4
- require 'distorted/font'
5
- require 'distorted-jekyll/static/text'
6
-
7
- module Jekyll
8
- module DistorteD
9
- module Static
10
- class Font < Text
11
-
12
- DRIVER = Cooltrainer::DistorteD::Font
13
-
14
- MEDIA_TYPE = DRIVER::MEDIA_TYPE
15
- MIME_TYPES = DRIVER::MIME_TYPES
16
-
17
- ATTRS = DRIVER::ATTRS
18
- ATTRS_DEFAULT = DRIVER::ATTRS_DEFAULT
19
- ATTRS_VALUES = DRIVER::ATTRS_VALUES
20
-
21
-
22
- # dest: String realpath to `_site` directory
23
- def write(dest)
24
- orig_dest = destination(dest)
25
-
26
- return false if !modified?
27
- self.class.mtimes[path] = mtime
28
-
29
- @distorted = DRIVER.new(
30
- path,
31
- demo: attr_value(:title),
32
- )
33
- FileUtils.cp(path, File.join(dd_dest(dest), @name))
34
-
35
- super
36
-
37
- end
38
-
39
- end # Text
40
- end # Static
41
- end # DistorteD
42
- end # Jekyll
@@ -1,55 +0,0 @@
1
- require 'fileutils'
2
- require 'set'
3
-
4
- require 'distorted/image'
5
- require 'distorted-jekyll/static/state'
6
-
7
- module Jekyll
8
- module DistorteD
9
- module Static
10
- class Image < Jekyll::DistorteD::Static::State
11
-
12
- DRIVER = Cooltrainer::DistorteD::Image
13
-
14
- MEDIA_TYPE = DRIVER::MEDIA_TYPE
15
- MIME_TYPES = DRIVER::MIME_TYPES
16
-
17
- ATTRS = DRIVER::ATTRS
18
- ATTRS_DEFAULT = DRIVER::ATTRS_DEFAULT
19
- ATTRS_VALUES = DRIVER::ATTRS_VALUES
20
-
21
-
22
- # dest: string realpath to `_site_` directory
23
- def write(dest)
24
- return false if File.exist?(path) && !modified?
25
- self.class.mtimes[path] = mtime
26
-
27
- # Create any directories to the depth of the intended destination.
28
- FileUtils.mkdir_p(dd_dest(dest))
29
-
30
- unless defined? @distorted
31
- @distorted = DRIVER.new(path)
32
- end
33
-
34
- Jekyll.logger.debug(@tag_name, "Rotating #{@name} if tagged.")
35
- @distorted.rotate(angle: :auto)
36
-
37
- # Save every desired variation of this image.
38
- # This will be a Set of Hashes each describing the name, type,
39
- # dimensions, attributes, etc of each output variation we want.
40
- # Full-size outputs will have the special tag `:full`.
41
- for variation in files
42
- if DRIVER::MIME_TYPES.include?(variation&.dig(:type))
43
- filename = File.join(dd_dest(dest), variation&.dig(:name) || @name)
44
- Jekyll.logger.debug('DistorteD Writing:', filename)
45
- @distorted.save(filename, width: variation&.dig(:width), crop: variation&.dig(:crop))
46
- end
47
- end
48
-
49
- true
50
- end
51
-
52
- end # Image
53
- end # Static
54
- end # DistorteD
55
- end # Jekyll
@@ -1,28 +0,0 @@
1
- require 'fileutils'
2
- require 'set'
3
-
4
- require 'distorted-jekyll/static/state'
5
-
6
- module Jekyll
7
- module DistorteD
8
- module Static
9
- class LastResort < Jekyll::DistorteD::Static::State
10
-
11
- # dest: string realpath to `_site_` directory
12
- def write(dest)
13
- return false if File.exist?(path) && !modified?
14
- self.class.mtimes[path] = mtime
15
-
16
- # Create any directories to the depth of the intended destination.
17
- FileUtils.mkdir_p(dd_dest(dest))
18
-
19
- Jekyll.logger.debug(@tag_name, "Copying #{@name} to #{dd_dest(dest)}")
20
- FileUtils.cp(path, File.join(dd_dest(dest), @name))
21
-
22
- true
23
- end
24
-
25
- end # Image
26
- end # Static
27
- end # DistorteD
28
- end # Jekyll
@@ -1,53 +0,0 @@
1
- require 'fileutils'
2
- require 'set'
3
-
4
- require 'distorted/pdf'
5
- require 'distorted-jekyll/static/pdf'
6
-
7
-
8
- module Jekyll
9
- module DistorteD
10
- module Static
11
- class PDF < Jekyll::DistorteD::Static::State
12
-
13
- DRIVER = Cooltrainer::DistorteD::PDF
14
-
15
- MEDIA_TYPE = DRIVER::MEDIA_TYPE
16
- SUB_TYPE = DRIVER::SUB_TYPE
17
- MIME_TYPES = DRIVER::MIME_TYPES
18
-
19
- ATTRS = DRIVER::ATTRS
20
- ATTRS_DEFAULT = DRIVER::ATTRS_DEFAULT
21
- ATTRS_VALUES = DRIVER::ATTRS_VALUES
22
-
23
-
24
- # dest: string realpath to `_site_` directory
25
- def write(dest)
26
- return false if File.exist?(path) && !modified?
27
- self.class.mtimes[path] = mtime
28
-
29
- # Create any directories to the depth of the intended destination.
30
- FileUtils.mkdir_p(dd_dest(dest))
31
-
32
- for variation in files
33
- if DRIVER::MIME_TYPES.include?(variation[:type])
34
- pdf_dest_path = File.join(dd_dest(dest), variation[:name])
35
-
36
- if true # TODO: Make this configurable
37
- Jekyll.logger.debug(@tag_name, "Optimizing #{@name} and copying to #{dd_dest(dest)}")
38
- # TODO: Make optimizations/plugins configurable
39
- DRIVER::optimize(path, pdf_dest_path)
40
- else
41
- Jekyll.logger.debug(@tag_name, "Copying #{@name} to #{dd_dest(dest)}")
42
- FileUtils.cp(path, pdf_dest_path)
43
- end
44
- end
45
- end
46
-
47
- true
48
- end
49
-
50
- end # PDF
51
- end # Static
52
- end # DistorteD
53
- end # Jekyll
@@ -1,141 +0,0 @@
1
- require 'set'
2
-
3
- require 'distorted-jekyll/molecule/abstract'
4
-
5
-
6
- module Jekyll
7
- module DistorteD
8
- module Static
9
- class State < Jekyll::StaticFile
10
-
11
- include Jekyll::DistorteD::Molecule::Abstract
12
-
13
- def initialize(
14
- site,
15
- base,
16
- dir,
17
- name,
18
- mime,
19
- attrs,
20
- dd_dest,
21
- url,
22
- collection: nil
23
- )
24
- # e.g. 'DistorteD::Static::Image' or 'DistorteD::Static::Video'
25
- @tag_name = self.class.name.split('::').drop(1).join('::').to_sym.freeze
26
-
27
- # String path to Jekyll site root
28
- @base = base
29
-
30
- # String container dir (under `base`) of original file
31
- @dir = dir
32
-
33
- # String filename of original file
34
- @name = name
35
-
36
- # Union Set of MIME::Types between the original media file
37
- # and the plugged MediaMolecule.
38
- @mime = mime
39
-
40
- # Attributes provided to our Liquid tag
41
- @attrs = attrs
42
-
43
- # String path to media generation output dir
44
- # under Site.dest (which is currently unknown)
45
- @dd_dest = dd_dest
46
-
47
- # String destination URL for the post/page on which the media appears.
48
- @url = url
49
-
50
- # Hello yes
51
- Jekyll.logger.debug(@tag_name, "#{base}/#{dir}/#{name} -> #{url}})")
52
-
53
- # Construct Jekyll::StaticFile with only the args it takes:
54
- super(
55
- site,
56
- base,
57
- dir,
58
- name,
59
- )
60
- end
61
-
62
- def basename
63
- File.basename(@name, '.*')
64
- end
65
-
66
- def extname
67
- File.extname(@name)
68
- end
69
-
70
- # Returns the to-be-written path of a single standard StaticFile.
71
- # The value returned by this method is only the 'main' or 'original'
72
- # (even if modified somehow) file and does not include the
73
- # path/filenames of any variations.
74
- # This method will be called by jekyll/lib/cleaner#new_files
75
- # to generate the list of files that need to be build or rebuilt
76
- # for a site. For this reason, this method shouldn't do any kind
77
- # of checking the real filesystem, since e.g. its URL-based
78
- # destdir might not exist yet if the Site.dest is completely blank.
79
- def destination(dest)
80
- File.join(dest, @dd_dest, @name)
81
- end
82
-
83
- # Return the absolute path to the top-level destination directory
84
- # of the currently-working media. This will usually be the same path
85
- # as the Jekyll post/page's generated HTML output.
86
- def dd_dest(dest)
87
- File.join(dest, @dd_dest)
88
- end
89
-
90
- # This method will be called by our monkey-patched Jekyll::Cleaner#new_files
91
- # in place of the single-destination method usually used.
92
- # This allows us to tell Jekyll about more than a single file
93
- # that should be kept when regenerating the site.
94
- # This makes DistorteD fast!
95
- def destinations(dest)
96
- # TODO: Make outputting the original file optional. Will need to change
97
- # templates, `modified?`s, and `generate`s to do that.
98
- filenames.map{|f| File.join(dd_dest(dest), f)} << destination(dest)
99
- end
100
-
101
- # HACK HACK HACK
102
- # Jekyll does not pass this method a site.dest like it does write() and
103
- # others, but I want to be able to short-circuit here if all the
104
- # to-be-generated files already exist.
105
- def modified?
106
- # Assume modified for the sake of freshness :)
107
- modified = true
108
-
109
- site_dest = Jekyll::DistorteD::Floor::config(:destination).to_s
110
- if Dir.exist?(site_dest)
111
-
112
- dd_dest = dd_dest(site_dest)
113
- if Dir.exist?(dd_dest)
114
-
115
- # TODO: Make outputting the original file conditional.
116
- # Doing that will require changing the default href handling
117
- # in the template, Jekyll::DistorteD::Static::State.destinations,
118
- # as well as Cooltrainer::DistorteD::Image.generate
119
- wanted_files = Set[@name].merge(filenames)
120
- extant_files = Dir.entries(dd_dest).to_set
121
-
122
- # TODO: Make this smarter. It's not enough that all the generated
123
- # filenames should exist. Try a few more ways to detect subtler
124
- # "changes to the source file since generation of variations.
125
- if wanted_files.subset?(extant_files)
126
- Jekyll.logger.debug(@name, "All variations present: #{wanted_files}")
127
- modified = false
128
- else
129
- Jekyll.logger.debug(@name, "Missing variations: #{wanted_files - extant_files}")
130
- end
131
-
132
- end # dd_dest.exists?
133
- end # site_dest.exists?
134
- Jekyll.logger.debug("#{@name} modified?", modified)
135
- return modified
136
- end
137
-
138
- end # state
139
- end # Static
140
- end # DistorteD
141
- end # Jekyll
@@ -1,52 +0,0 @@
1
- require 'fileutils'
2
- require 'set'
3
-
4
-
5
- require 'distorted-jekyll/static/image'
6
-
7
- module Jekyll
8
- module DistorteD
9
- module Static
10
- class SVG < Jekyll::DistorteD::Static::Image
11
-
12
- DRIVER = Cooltrainer::DistorteD::SVG
13
-
14
- MEDIA_TYPE = DRIVER::MEDIA_TYPE
15
- SUB_TYPE = DRIVER::SUB_TYPE
16
- MIME_TYPES = DRIVER::MIME_TYPES
17
-
18
- ATTRS = DRIVER::ATTRS
19
- ATTRS_DEFAULT = DRIVER::ATTRS_DEFAULT
20
- ATTRS_VALUES = DRIVER::ATTRS_VALUES
21
-
22
-
23
- # dest: string realpath to `_site_` directory
24
- def write(dest)
25
- return false if File.exist?(path) && !modified?
26
- self.class.mtimes[path] = mtime
27
-
28
- # Create any directories to the depth of the intended destination.
29
- FileUtils.mkdir_p(dd_dest(dest))
30
-
31
- for variation in files
32
- if DRIVER::MIME_TYPES.include?(variation[:type])
33
- svg_dest_path = File.join(dd_dest(dest), variation[:name])
34
-
35
- if true # TODO: Make this configurable
36
- Jekyll.logger.debug(@tag_name, "Optimizing #{@name} and copying to #{dd_dest(dest)}")
37
- DRIVER::optimize(path, svg_dest_path)
38
- else
39
- Jekyll.logger.debug(@tag_name, "Copying #{@name} to #{dd_dest(dest)}")
40
- FileUtils.cp(path, svg_dest_path)
41
- end
42
- end
43
- end
44
-
45
- super # Generate raster Image variations
46
- true
47
- end
48
-
49
- end
50
- end
51
- end
52
- end
@@ -1,57 +0,0 @@
1
- require 'fileutils'
2
- require 'set'
3
-
4
- require 'distorted/text'
5
- require 'distorted-jekyll/static/image'
6
-
7
- module Jekyll
8
- module DistorteD
9
- module Static
10
- class Text < Image
11
-
12
- DRIVER = Cooltrainer::DistorteD::Text
13
-
14
- MEDIA_TYPE = DRIVER::MEDIA_TYPE
15
- MIME_TYPES = DRIVER::MIME_TYPES
16
-
17
- ATTRS = DRIVER::ATTRS
18
- ATTRS_DEFAULT = DRIVER::ATTRS_DEFAULT
19
- ATTRS_VALUES = DRIVER::ATTRS_VALUES
20
-
21
-
22
- # dest: String realpath to `_site` directory
23
- def write(dest)
24
- orig_dest = destination(dest)
25
-
26
- return false if !modified?
27
- self.class.mtimes[path] = mtime
28
-
29
- unless defined? @distorted
30
- @distorted = DRIVER.new(
31
- path,
32
- encoding: attr_value(:encoding),
33
- font: attr_value(:font),
34
- spacing: attr_value(:spacing),
35
- dpi: attr_value(:dpi),
36
- )
37
- end
38
- # Write any actual-text output variations.
39
- # Images will be written by `super`.
40
- for variation in files
41
- if DRIVER::MIME_TYPES.include?(variation&.dig(:type))
42
- filename = File.join(dd_dest(dest), variation&.dig(:name) || @name)
43
- Jekyll.logger.debug('DistorteD Writing:', filename)
44
- # TODO: For now this is just copying the file, but we should
45
- # probably support some sort of UTF conversion or something here.
46
- FileUtils.cp(path, filename)
47
- end
48
- end
49
-
50
- super
51
-
52
- end
53
-
54
- end # Text
55
- end # Static
56
- end # DistorteD
57
- end # Jekyll