jekyll-plus 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +77 -0
  4. data/lib/jekyll-plus.rb +2 -0
  5. data/lib/jekyll-plus/version.rb +3 -0
  6. data/lib/jekyll/commands/new.rb +190 -0
  7. data/lib/jekyll/templates/classic_template/Gemfile.erb +26 -0
  8. data/lib/jekyll/templates/classic_template/_config.yml.erb +37 -0
  9. data/lib/jekyll/templates/classic_template/theme_folders/_includes/disqus_comments.html +20 -0
  10. data/lib/jekyll/templates/classic_template/theme_folders/_includes/footer.html +46 -0
  11. data/lib/jekyll/templates/classic_template/theme_folders/_includes/google-analytics.html +11 -0
  12. data/lib/jekyll/templates/classic_template/theme_folders/_includes/head.html +16 -0
  13. data/lib/jekyll/templates/classic_template/theme_folders/_includes/header.html +27 -0
  14. data/lib/jekyll/templates/classic_template/theme_folders/_includes/icon-github.html +1 -0
  15. data/lib/jekyll/templates/classic_template/theme_folders/_includes/icon-github.svg +1 -0
  16. data/lib/jekyll/templates/classic_template/theme_folders/_includes/icon-twitter.html +1 -0
  17. data/lib/jekyll/templates/classic_template/theme_folders/_includes/icon-twitter.svg +1 -0
  18. data/lib/jekyll/templates/classic_template/theme_folders/_layouts/default.html +20 -0
  19. data/lib/jekyll/templates/classic_template/theme_folders/_layouts/home.html +25 -0
  20. data/lib/jekyll/templates/classic_template/theme_folders/_layouts/page.html +14 -0
  21. data/lib/jekyll/templates/classic_template/theme_folders/_layouts/post.html +18 -0
  22. data/lib/jekyll/templates/classic_template/theme_folders/_sass/_base.scss +198 -0
  23. data/lib/jekyll/templates/classic_template/theme_folders/_sass/_layout.scss +237 -0
  24. data/lib/jekyll/templates/classic_template/theme_folders/_sass/_syntax-highlighting.scss +71 -0
  25. data/lib/jekyll/templates/classic_template/theme_folders/assets/main.scss +47 -0
  26. data/lib/jekyll/templates/site_template/.gitignore +3 -0
  27. data/lib/jekyll/templates/site_template/Gemfile.erb +24 -0
  28. data/lib/jekyll/templates/site_template/_config.yml.erb +37 -0
  29. data/lib/jekyll/templates/site_template/_posts/0000-00-00-welcome-to-jekyll.md.erb +25 -0
  30. data/lib/jekyll/templates/site_template/about.md +15 -0
  31. data/lib/jekyll/templates/site_template/index.md +6 -0
  32. metadata +131 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d61d7047840f274b66bfbae1c9e987cb304ba6fb
4
+ data.tar.gz: c9bf197e497d800e3515a9d591e898cae0bf7b0f
5
+ SHA512:
6
+ metadata.gz: ee0170d39c872f61bcd51b7bc4b3b835d595aec9fa90b2fcc54bd02f7f57421a4f851b1725cdc9021b8bf80d037289879c1cef406c80454511b158579cdc497c
7
+ data.tar.gz: 15a4d19d35f2c921c33953ce77aee115515d76d6a44c2bf805de38fadc41f541705b393594a6bd56840c880a4afbabe275fe0c763c2c5025faf92c9e38e3d6b1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 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.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # Jekyll-Plus
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/jekyll-plus.svg)](https://rubygems.org/gems/jekyll-plus)
4
+ [![Build Status](https://img.shields.io/travis/ashmaroli/jekyll-plus/master.svg?label=Build%20Status)][travis]
5
+
6
+ [travis]: https://travis-ci.org/ashmaroli/jekyll-plus
7
+
8
+ A ruby gem that modifies `jekyll new` command to add new switches: `--plus`, `--classic`, `--verbose`.
9
+
10
+ ## Installation
11
+
12
+ Simply run:
13
+
14
+ $ gem install jekyll-plus
15
+
16
+ Currently, to use this gem as intended, Jekyll's native `~/commands/new.rb` file requires to be slightly modified as shown below:
17
+ ```diff
18
+ # lib/jekyll/commands/new.rb
19
+
20
+ def init_with_program(prog)
21
+ prog.command(:new) do |c|
22
+ c.syntax "new PATH"
23
+ c.description "Creates a new Jekyll site scaffold in PATH"
24
+
25
+ c.option "force", "--force", "Force creation even if PATH already exists"
26
+ c.option "blank", "--blank", "Creates scaffolding but with empty files"
27
+ c.option "skip-bundle", "--skip-bundle", "Skip 'bundle install'"
28
+ + c.option "plus", "--plus", "Plus features"
29
+ + c.option "classic", "--classic", "Classic Jekyll scaffolding"
30
+ + c.option "verbose", "--verbose", "Output messages while creating"
31
+
32
+ c.action do |args, options|
33
+ + if options["plus"] || options["classic"] || options["verbose"]
34
+ + External.require_with_graceful_fail "jekyll-plus"
35
+ + end
36
+ Jekyll::Commands::New.process(args, options)
37
+ end
38
+ end
39
+ end
40
+ ```
41
+ ## Usage
42
+
43
+ This gem provides three new switches to be used along with the `jekyll new` command.
44
+
45
+ ### `--plus`
46
+
47
+ This switch creates a new Jekyll site using ERB templates for `_config.yml` and `Gemfile` and additionally initializes the directory as a git repository.
48
+ The config file in such sites will be **pre-populated** with information from the argument(s) passed to `jekyll new` and from the user's `.gitconfig` file. If the git-user-details have not been configured, placeholder text will be used instead.
49
+
50
+ **Note:** `site.title` will be set with `capitalized` version of the project's directory-name.
51
+ This switch has no effect when used alongside the `--blank` switch.
52
+
53
+ ### `--classic`
54
+
55
+ This switch creates a classic-style (pre-Jekyll-3.2) Jekyll site by including the `_layouts`, `_includes`, `_sass` at the root. The directory structure has been altered to be in sync with Jekyll v3.3 and hence you'll have a `Gemfile`, `css/main.scss` is now `assets/main.scss`, etc.
56
+
57
+ A *Classic Site* will:
58
+ - have `Gemfile` and `_config.yml` with the line containing `minima` commented out.
59
+ - have `_layouts`, `_includes`, `_sass` and `assets` at root.
60
+ - the contents of these directories, in sync (to be manually updated with patch releases) with the latest `master` branch from Minima Repo.
61
+ - ***not*** have `site.email` and `site.author` pre-filled with info from user's `.gitconfig` or `site.title` pre-configured from the argument(s) passed.
62
+ - ***not*** run `bundle install` automatically.
63
+
64
+ **Note:** `--classic` dominates `--plus` and will create a *Classic Site* when the two switches are used together.
65
+
66
+ ### `--verbose`
67
+
68
+ This switch prints out messages as the new Jekyll site is being created. Can be used with `--blank`, `--plus` and `--classic`.
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ashmaroli/jekyll-plus. 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.
73
+
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "jekyll-plus/version"
2
+ require_relative "jekyll/commands/new"
@@ -0,0 +1,3 @@
1
+ module JekyllPlus
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,190 @@
1
+ require "erb"
2
+
3
+ module Jekyll
4
+ class Commands::New < Command
5
+ class << self
6
+ def init_with_program(prog)
7
+ end
8
+
9
+ def process(args, options = {})
10
+ @verbose = options["verbose"]
11
+
12
+ raise ArgumentError, "You must specify a path." if args.empty?
13
+
14
+ # extract capitalized blog title from the argument(s) when a 'path'
15
+ # to the new site has been provided.
16
+ # e.g. jekyll new work/blogs/exploring ruby would install a blog
17
+ # titled 'Exploring Ruby' at path ~/work/blogs/exploring ruby
18
+ blog_title = extract_title args
19
+ blog_path = File.expand_path(args.join(" "), Dir.pwd)
20
+ FileUtils.mkdir_p blog_path
21
+
22
+ if preserve_source_location?(blog_path, options)
23
+ Jekyll.logger.abort_with "Conflict:",
24
+ "#{blog_path} exists and is not empty."
25
+ end
26
+
27
+ create_site blog_title, blog_path, options
28
+ end
29
+
30
+ #
31
+ # private methods
32
+ #
33
+
34
+ private
35
+
36
+ # join the arguments given, with a whitespace; replace backslashes, if any
37
+ # with a forward slash; split the string into an array again and select the
38
+ # last entry.
39
+ # Further split the entry along a single whitespace, and map to a new array
40
+ # after capitalizing the split-entries. Join them again with a whitespace
41
+ # to form the final title string.
42
+ def extract_title(args)
43
+ a = args.join(" ").tr("\\", "/").split("/").last
44
+ a.split.map(&:capitalize).join(" ")
45
+ end
46
+
47
+ def initialized_post_name
48
+ "_posts/#{Time.now.strftime("%Y-%m-%d")}-welcome-to-jekyll.md"
49
+ end
50
+
51
+ def initialize_git(path)
52
+ Jekyll.logger.info "Initialising:", File.join(path, ".git") if @verbose
53
+ Dir.chdir(path) { `git init` }
54
+ end
55
+
56
+ def user_name
57
+ name ||= `git config user.name`.chomp
58
+ name.empty? ? "Github User" : name
59
+ end
60
+
61
+ def user_email
62
+ email ||= `git config user.email`.chomp
63
+ email.empty? ? "your-email@domain.com" : email
64
+ end
65
+
66
+ def preserve_source_location?(path, options)
67
+ !options["force"] && !Dir["#{path}/**/*"].empty?
68
+ end
69
+
70
+ def create_site(title, path, options)
71
+ if options["blank"] && options["verbose"]
72
+ create_blank_site path
73
+ else
74
+ create_sample_files path
75
+ add_supporting_files title, path, options
76
+ end
77
+ after_install title, path, options
78
+ end
79
+
80
+ def create_blank_site(path)
81
+ Dir.chdir(path) do
82
+ FileUtils.mkdir(%w(_layouts _posts _drafts))
83
+ FileUtils.touch("index.html")
84
+ end
85
+ end
86
+
87
+ def create_sample_files(path)
88
+ Jekyll.logger.info "" if @verbose
89
+ initialize_git path
90
+ FileUtils.mkdir_p(File.expand_path("_posts", path))
91
+ source = site_template
92
+
93
+ static_files = %w(index.md about.md .gitignore)
94
+ static_files.each do |file|
95
+ write_file(file, template(file, source), path)
96
+ end
97
+ write_file(initialized_post_name, template(scaffold_path, source), path)
98
+ end
99
+
100
+ # adds Gemfile and _config.yml
101
+ # additionally creates (updated) SCAFFOLD DIRECTORIES of a Jekyll Theme at
102
+ # blog_path when the `--classic` switch is used.
103
+ def add_supporting_files(title, path, options)
104
+ if options["classic"]
105
+ source = classic_template
106
+ Jekyll.logger.info "Creating:", "Classic directories and files" if @verbose
107
+ FileUtils.cp_r "#{classic_directories}/.", path
108
+ else
109
+ source = site_template
110
+ end
111
+ create_config_file title, path, source
112
+ write_file("Gemfile", template("Gemfile.erb", source), path)
113
+ Jekyll.logger.info "" if @verbose
114
+ end
115
+
116
+ # create _config.yml pre-populated with blog-title, and author's name & email
117
+ # using information from the user's .gitconfig
118
+ def create_config_file(title, path, source)
119
+ @blog_title = title
120
+ @user_name = user_name
121
+ @user_email = user_email
122
+ config_template = File.expand_path("_config.yml.erb", source)
123
+ config_copy = ERB.new(File.read(config_template)).result(binding)
124
+
125
+ Jekyll.logger.info "Creating:", File.join(path, "_config.yml") if @verbose
126
+ File.open(File.expand_path("_config.yml", path), "w") do |f|
127
+ f.write(config_copy)
128
+ end
129
+ end
130
+
131
+ def write_file(filename, contents, path)
132
+ full_path = File.expand_path(filename, path)
133
+ Jekyll.logger.info "Creating:", full_path if @verbose
134
+ File.write(full_path, contents)
135
+ end
136
+
137
+ def template(filename, source)
138
+ erb ||= ThemeBuilder::ERBRenderer.new(self)
139
+ erb.render(File.read(File.expand_path(filename, source)))
140
+ end
141
+
142
+ def site_template
143
+ File.expand_path("../templates/site_template", File.dirname(__FILE__))
144
+ end
145
+
146
+ def classic_template
147
+ File.expand_path("../templates/classic_template", File.dirname(__FILE__))
148
+ end
149
+
150
+ def classic_directories
151
+ File.join(classic_template, "theme_folders")
152
+ end
153
+
154
+ def scaffold_path
155
+ "_posts/0000-00-00-welcome-to-jekyll.md.erb"
156
+ end
157
+
158
+ # After a new blog has been installed, print a success notification and then
159
+ # automatically execute bundle install from within the new blog dir unless
160
+ # the user opts to generate a classic Jekyll blog or a blank blog or skip
161
+ # 'bundle install' using the `--skip-bundle` switch
162
+ def after_install(title, path, options)
163
+ if options["classic"]
164
+ Jekyll.logger.info "New classic jekyll site installed in #{path.cyan}."
165
+ elsif options["blank"]
166
+ Jekyll.logger.info "New blank jekyll site installed in #{path.cyan}."
167
+ else
168
+ Jekyll.logger.info "New jekyll site #{title.cyan} installed in #{path.cyan}."
169
+ end
170
+
171
+ Jekyll.logger.info "Bundle install skipped." if options["skip-bundle"]
172
+ unless options["classic"] || options["blank"] || options["skip-bundle"]
173
+ bundle_install path
174
+ end
175
+ end
176
+
177
+ def bundle_install(path)
178
+ Jekyll::External.require_with_graceful_fail "bundler"
179
+ Jekyll.logger.info "Running bundle install in #{path.cyan}..."
180
+ Dir.chdir(path) do
181
+ if ENV["CI"]
182
+ system("bundle", "install", "--quiet")
183
+ else
184
+ system("bundle", "install")
185
+ end
186
+ end
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,26 @@
1
+ source "https://rubygems.org"
2
+ ruby "<%= RUBY_VERSION %>"
3
+
4
+ # Hello! This is where you manage which Jekyll version is used to run.
5
+ # When you want to use a different version, change it below, save the
6
+ # file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
7
+ #
8
+ # bundle exec jekyll serve
9
+ #
10
+ # This will help ensure the proper Jekyll version is running.
11
+ # Happy Jekylling!
12
+ gem "jekyll", "~> <%= Jekyll::VERSION %>"
13
+
14
+ # This is the default theme for new Jekyll sites. You may uncomment the line
15
+ # below and change to any other theme-gem. Don't forget to run `bundle install`
16
+ # again after you change the setting.
17
+ # gem "minima"
18
+
19
+ # If you want to use GitHub Pages, remove the "gem "jekyll"" above and
20
+ # uncomment the line below. To upgrade, run `bundle update github-pages`.
21
+ # gem "github-pages", group: :jekyll_plugins
22
+
23
+ # If you have any plugins, put them here!
24
+ group :jekyll_plugins do
25
+ gem "jekyll-feed", "~> 0.6"
26
+ end
@@ -0,0 +1,37 @@
1
+ # Welcome to Jekyll!
2
+ #
3
+ # This config file is meant for settings that affect your whole blog, values
4
+ # which you are expected to set up once and rarely edit after that. If you find
5
+ # yourself editing this file very often, consider using Jekyll's data files
6
+ # feature for the data you need to update frequently.
7
+ #
8
+ # For technical reasons, this file is *NOT* reloaded automatically when you use
9
+ # 'bundle exec jekyll serve'. If you change this file, please restart the server process.
10
+
11
+ # Site settings
12
+ # These are used to personalize your new site. If you look in the HTML files,
13
+ # you will see them accessed via {{ site.title }}, {{ site.email }}, and so on.
14
+ # You can create any custom variable you would like, and they will be accessible
15
+ # in the templates via {{ site.myvariable }}.
16
+
17
+ title: your awesome title
18
+ email: your-email@domain.com
19
+ # the ">" below means to ignore newlines until "baseurl:"
20
+ description: >
21
+ Write an awesome description for your new site here. You can edit this
22
+ line in _config.yml. It will appear in your document head meta (for
23
+ Google search results) and in your feed.xml site description.
24
+ baseurl: "" # the subpath of your site, e.g. /blog
25
+ url: "" # the base hostname & protocol for your site, e.g. http://example.com
26
+ twitter_username: jekyllrb
27
+ github_username: jekyll
28
+
29
+ # Build settings
30
+ markdown: kramdown
31
+ # uncomment (and edit) the line below when using a theme
32
+ # theme: minima
33
+ gems:
34
+ - jekyll-feed
35
+ exclude:
36
+ - Gemfile
37
+ - Gemfile.lock
@@ -0,0 +1,20 @@
1
+ {% if page.comments != false and jekyll.environment == "production" %}
2
+
3
+ <div id="disqus_thread"></div>
4
+ <script>
5
+ var disqus_config = function () {
6
+ this.page.url = '{{ page.url | absolute_url }}';
7
+ this.page.identifier = '{{ page.url | absolute_url }}';
8
+ };
9
+
10
+ (function() {
11
+ var d = document, s = d.createElement('script');
12
+
13
+ s.src = 'https://{{ site.disqus.shortname }}.disqus.com/embed.js';
14
+
15
+ s.setAttribute('data-timestamp', +new Date());
16
+ (d.head || d.body).appendChild(s);
17
+ })();
18
+ </script>
19
+ <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
20
+ {% endif %}
@@ -0,0 +1,46 @@
1
+ <footer class="site-footer">
2
+
3
+ <div class="wrapper">
4
+
5
+ <h2 class="footer-heading">{{ site.title | escape }}</h2>
6
+
7
+ <div class="footer-col-wrapper">
8
+ <div class="footer-col footer-col-1">
9
+ <ul class="contact-list">
10
+ <li>
11
+ {% if site.author %}
12
+ {{ site.author | escape }}
13
+ {% else %}
14
+ {{ site.title | escape }}
15
+ {% endif %}
16
+ </li>
17
+ {% if site.email %}
18
+ <li><a href="mailto:{{ site.email }}">{{ site.email }}</a></li>
19
+ {% endif %}
20
+ </ul>
21
+ </div>
22
+
23
+ <div class="footer-col footer-col-2">
24
+ <ul class="social-media-list">
25
+ {% if site.github_username %}
26
+ <li>
27
+ {% include icon-github.html username=site.github_username %}
28
+ </li>
29
+ {% endif %}
30
+
31
+ {% if site.twitter_username %}
32
+ <li>
33
+ {% include icon-twitter.html username=site.twitter_username %}
34
+ </li>
35
+ {% endif %}
36
+ </ul>
37
+ </div>
38
+
39
+ <div class="footer-col footer-col-3">
40
+ <p>{{ site.description | escape }}</p>
41
+ </div>
42
+ </div>
43
+
44
+ </div>
45
+
46
+ </footer>
@@ -0,0 +1,11 @@
1
+ <script>
2
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
3
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
4
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
5
+ })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
6
+
7
+ ga('create', '{{ site.google_analytics }}', 'auto');
8
+ ga('send', 'pageview');
9
+
10
+ </script>
11
+