jekyll-extract 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 62fd817b191162e43f68e6c932a74b54e95a4956
4
+ data.tar.gz: 94029b5b0a3729c969ee1cb5d6a403ae97f05803
5
+ SHA512:
6
+ metadata.gz: 81a9156f826262e48e925d29b63e606cea490dba6b654b688d318cd084eef106d657472341a2a17fa219942f1a02b454974b6d4eec3d3a6ed3f9d3dc12c7a697
7
+ data.tar.gz: edb7166db5db49c3a4fa37fbb6bbf5970bd60cd7c8d86eae61447232c3599bc941546cc7aea1b519f39cc5ceb7142d5d81deb8c4232d6aeaaee659170522636b
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Ashwin Maroli
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,97 @@
1
+ # Jekyll Extract
2
+
3
+ A plugin that adds a new Jekyll command to easily copy files and directories from a theme-gem to your site's source directory.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this plugin to your site's Gemfile:
9
+
10
+ ```ruby
11
+ group :jekyll_plugins do
12
+ gem "jekyll-extract"
13
+ end
14
+ ```
15
+ ...and run:
16
+
17
+ $ bundle
18
+
19
+
20
+ ## Usage
21
+
22
+ `jekyll extract` command is meant to simplify accessing a Jekyll theme-gem and copying the files you wish to customize, to your site's configured source directory.
23
+
24
+ Run `jekyll extract` with a `--list-all` switch to get an idea about all files bundled in the current theme:
25
+
26
+ ```sh
27
+ # demo using Minima v2.1.1
28
+
29
+ $ bundle exec jekyll extract --list-all
30
+ [...]
31
+ Listing: All files in current theme
32
+ * assets/main.scss
33
+ * LICENSE.txt
34
+ * README.md
35
+ * _includes/disqus_comments.html
36
+ * _includes/footer.html
37
+ * _includes/google-analytics.html
38
+ * _includes/head.html
39
+ * _includes/header.html
40
+ * _includes/icon-github.html
41
+ * _includes/icon-github.svg
42
+ * _includes/icon-twitter.html
43
+ * _includes/icon-twitter.svg
44
+ * _layouts/default.html
45
+ * _layouts/home.html
46
+ * _layouts/page.html
47
+ * _layouts/post.html
48
+ * _sass/minima/_base.scss
49
+ * _sass/minima/_layout.scss
50
+ * _sass/minima/_syntax-highlighting.scss
51
+ * _sass/minima.scss
52
+ ```
53
+
54
+ To copy an entire directory over to the source directory (henceforth referenced by the phrase *"extract to source"*), pass the directory-path, relative to the gem, as the argument:
55
+
56
+ ```sh
57
+ $ bundle exec jekyll extract _layouts
58
+ ```
59
+
60
+ To extract multiple directories simultaneously, pass each directory path as arguments:
61
+
62
+ ```sh
63
+ $ bundle exec jekyll extract _layouts _sass/minima
64
+ ```
65
+ will extract contents of both `_layouts` and `_sass/minima` to source, creating the directories as required.
66
+
67
+ Similarly extract certain files like below:
68
+
69
+ To check what files are bundled in a particular directory, run the command with a `--show` switch:
70
+
71
+ ```sh
72
+ $ bundle exec jekyll extract _layouts --show
73
+ [...]
74
+ Listing: Contents of '_layouts' in theme gem...
75
+ * _layouts/default.html
76
+ * _layouts/home.html
77
+ * _layouts/page.html
78
+ * _layouts/post.html
79
+
80
+ ```
81
+ Now, to extract just a couple of layouts from the list, run:
82
+
83
+ ```sh
84
+ $ bundle exec jekyll extract _layouts/default.html _layouts/page.html
85
+ ```
86
+ The above command will extract these two files to your site's source directory.
87
+
88
+
89
+ ## Contributing
90
+
91
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ashmaroli/jekyll-extract. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
92
+
93
+
94
+ ## License
95
+
96
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
97
+
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ autoload :ThemeGemExtractor, "theme_gem_extractor"
5
+
6
+ module Commands
7
+ class Extract < Command
8
+ class << self
9
+ def init_with_program(prog)
10
+ prog.command(:extract) do |c|
11
+ c.syntax "extract [DIR (or) FILE-PATH] [options]"
12
+ c.description "Extract theme-gem contents to source directory"
13
+
14
+ c.option "show", "--show", "List the contents of the specified [DIR]"
15
+ c.option "force", "--force", "Force extraction even if file already exists"
16
+ c.option "list-all", "--list-all", "List all files in the theme-gem"
17
+
18
+ c.action do |args, options|
19
+ process(args, options)
20
+ end
21
+ end
22
+ end
23
+
24
+ def process(args, options = {})
25
+ unless options["list-all"]
26
+ raise ArgumentError, "You must specify a path." if args.empty?
27
+ end
28
+
29
+ config = Jekyll.configuration(options)
30
+ @site ||= Site.new(config)
31
+
32
+ Jekyll.logger.info "Source Directory:", config["source"]
33
+ Jekyll.logger.info "Theme Directory:", @site.theme.root
34
+ puts ""
35
+
36
+ return list_all_files if options["list-all"]
37
+
38
+ # Substitute leading special-characters in an argument with an
39
+ # 'underscore' to disable extraction of files outside the theme-gem
40
+ # but allow extraction of theme directories with a leading underscore.
41
+ #
42
+ # Process each valid argument individually to enable extraction of
43
+ # multiple files or directories.
44
+ args.map { |i| i.sub(%r!\A\W!, "_") }.each do |arg|
45
+ ThemeGemExtractor.new(@site, options).extract arg
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def list_all_files
52
+ Jekyll.logger.info "Listing:", "All files in current theme"
53
+ Dir["#{@site.theme.root}/**/*"].each do |file|
54
+ next if File.directory?(file)
55
+ Jekyll.logger.info "",
56
+ " * #{file.sub(@site.in_theme_dir("/"), "")}"
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ class ThemeGemExtractor
5
+ attr_reader :site, :options, :theme_root
6
+
7
+ def initialize(site, options)
8
+ @site = site
9
+ @options = options
10
+ @theme_root = site.in_theme_dir("/")
11
+ end
12
+
13
+ def extract(path)
14
+ file_path = site.in_theme_dir path
15
+ unless File.exist?(file_path)
16
+ puts ""
17
+ raise ArgumentError,
18
+ "Specified path #{path.yellow} doesn't exist in the theme-gem."
19
+ end
20
+ extract_to_source file_path
21
+ end
22
+
23
+ def extract_to_source(path)
24
+ return list_contents(path) if options["show"]
25
+
26
+ if File.directory? path
27
+ extract_directory_contents path
28
+ else
29
+ extract_file_with_directory path
30
+ end
31
+ end
32
+
33
+ def extract_directory_contents(path)
34
+ destination = site.in_source_dir relative_path(path)
35
+ if File.exist?(destination) && !options["force"]
36
+ already_exists_msg path
37
+ else
38
+ extract_contents path, destination
39
+ end
40
+ end
41
+
42
+ def extract_contents(source, destination)
43
+ FileUtils.cp_r "#{source}/.", destination
44
+ files_in(source).each do |file|
45
+ extraction_msg file
46
+ end
47
+ rescue Errno::ENOENT
48
+ FileUtils.mkdir_p destination
49
+ retry
50
+ end
51
+
52
+ def extract_file_with_directory(file_path)
53
+ file = file_path.split("/").last
54
+ dir_path = File.dirname(
55
+ site.in_source_dir(relative_path(file_path))
56
+ )
57
+ FileUtils.mkdir_p dir_path
58
+
59
+ if File.exist?(File.join(dir_path, file)) && !options["force"]
60
+ already_exists_msg file_path
61
+ else
62
+ FileUtils.cp_r file_path, dir_path
63
+ extraction_msg file_path
64
+ end
65
+ end
66
+
67
+ def list_contents(path)
68
+ if File.directory? path
69
+ directory_listing path
70
+ else
71
+ Jekyll.logger.warn "", "The --show switch only works for directories"
72
+ end
73
+ end
74
+
75
+ def directory_listing(path)
76
+ Jekyll.logger.info "Listing:",
77
+ "Contents of '#{relative_path(path)}' in theme gem..."
78
+
79
+ files_in(path).each do |file|
80
+ Jekyll.logger.info "", " * #{relative_path(file)}"
81
+ end
82
+ end
83
+
84
+ def files_in(dir_path)
85
+ Dir["#{dir_path}/**/*"].reject { |d| File.directory? d }
86
+ end
87
+
88
+ def relative_path(path)
89
+ path.sub theme_root, ""
90
+ end
91
+
92
+ def extraction_msg(file)
93
+ Jekyll.logger.info "Extract:", relative_path(file)
94
+ end
95
+
96
+ def already_exists_msg(file)
97
+ Jekyll.logger.warn "Error:", "'#{relative_path(file)}' already " \
98
+ "exists at destination. Use --force to overwrite."
99
+ end
100
+ end
101
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-extract
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ashwin Maroli
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-07 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: '3.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
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.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.49.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.49.1
55
+ description:
56
+ email:
57
+ - ashmaroli@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - README.md
64
+ - lib/jekyll-extract.rb
65
+ - lib/theme_gem_extractor.rb
66
+ homepage: https://github.com/ashmaroli/jekyll-extract
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.6.10
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: A Jekyll command to easily copy theme-gem contents to source directory.
90
+ test_files: []