jekyll-github-pages-gem 1.0.0 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e96acc9371c59ba0163040fc42595a54ec2dc7602b9d128313cb1b05d2c4106
4
- data.tar.gz: 5310d22171f0150137e9abdbac7c0d3147f47f27f84f1c3c240c664e0033baef
3
+ metadata.gz: 9482ae3d917e1f9d824bf20f244ba5408a794292c212a356b4fcb58776fb03f9
4
+ data.tar.gz: 83b6a7c8cb8ced7f48a85b58b14444f8192f32d6914a7738ab69220767cbb14d
5
5
  SHA512:
6
- metadata.gz: 07c6be16e280cd410f7a0f5c25e16ea7fdbd69611a2a7fb61ec19846428b4ca2fe53a48eb0aec9504b8532b17bb6de815bbde38fc0ce82c6a71e83f0e47881c3
7
- data.tar.gz: d9cdef19e6748af33fcd01c8dd1a30fb6a032b38839b924d168b26789720e63aeb032002e7cdbc699fb55f2bf58b45ea13fb6ca7a0c395e4c368a245da4743e8
6
+ metadata.gz: 65367b9e37826aed8409952ee2bd4f8d68989c4e1275f37d735f3cf22891e3df8055e0d52a9b74d7d9ebbaed2b272dc0f3607b23d99a04520f22e60c1ecf8764
7
+ data.tar.gz: c4463b7d5f5d079da7c96ddd425726fb5ba35e0d9f86744579b122b2affdb6659984c2c6a56c057b432f1dc695dafa83e2b144018bf4b97ec8b5e307b17768bd
data/Gemfile CHANGED
@@ -3,7 +3,7 @@
3
3
  source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
- gem 'kramdown'
6
+ gem 'kramdown', '~> 2.3.0'
7
7
 
8
8
  gem 'octokit', '~> 4.18'
9
9
 
@@ -16,6 +16,8 @@ gem 'faraday', '~> 0.17.1'
16
16
 
17
17
  gem 'rake'
18
18
 
19
+ gem 'rdoc'
20
+
19
21
  group :test do
20
22
  gem 'minitest'
21
23
  gem 'mocha'
@@ -1,22 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-github-pages-gem (1.0.0)
4
+ jekyll-github-pages-gem (1.1.2)
5
+ carrierwave (>= 2.0.0.rc, < 3.0)
6
+ kramdown (~> 2.3.0)
7
+ octokit (~> 4.18)
5
8
 
6
9
  GEM
7
10
  remote: https://rubygems.org/
8
11
  specs:
9
- activemodel (6.0.2.2)
10
- activesupport (= 6.0.2.2)
11
- activesupport (6.0.2.2)
12
+ activemodel (6.0.3.2)
13
+ activesupport (= 6.0.3.2)
14
+ activesupport (6.0.3.2)
12
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
16
  i18n (>= 0.7, < 2)
14
17
  minitest (~> 5.1)
15
18
  tzinfo (~> 1.1)
16
- zeitwerk (~> 2.2)
19
+ zeitwerk (~> 2.2, >= 2.2.2)
17
20
  addressable (2.7.0)
18
21
  public_suffix (>= 2.0.2, < 5.0)
19
- ast (2.4.0)
22
+ ast (2.4.1)
20
23
  carrierwave (2.1.0)
21
24
  activemodel (>= 5.0.0)
22
25
  activesupport (>= 5.0.0)
@@ -24,43 +27,47 @@ GEM
24
27
  image_processing (~> 1.1)
25
28
  mimemagic (>= 0.3.0)
26
29
  mini_mime (>= 0.1.3)
27
- concurrent-ruby (1.1.6)
30
+ concurrent-ruby (1.1.7)
28
31
  docile (1.3.2)
29
32
  faraday (0.17.3)
30
33
  multipart-post (>= 1.2, < 3)
31
- ffi (1.12.2)
32
- ffi (1.12.2-x64-mingw32)
33
- i18n (1.8.2)
34
+ ffi (1.13.1-x64-mingw32)
35
+ i18n (1.8.5)
34
36
  concurrent-ruby (~> 1.0)
35
- image_processing (1.10.3)
37
+ image_processing (1.11.0)
36
38
  mini_magick (>= 4.9.5, < 5)
37
39
  ruby-vips (>= 2.0.17, < 3)
38
- jaro_winkler (1.5.4)
39
- kramdown (2.1.0)
40
- mimemagic (0.3.4)
40
+ kramdown (2.3.0)
41
+ rexml
42
+ mimemagic (0.3.5)
41
43
  mini_magick (4.10.1)
42
44
  mini_mime (1.0.2)
43
- minitest (5.14.0)
45
+ minitest (5.14.1)
44
46
  mocha (1.11.2)
45
47
  multipart-post (2.1.1)
46
48
  octokit (4.18.0)
47
49
  faraday (>= 0.9)
48
50
  sawyer (~> 0.8.0, >= 0.5.3)
49
- parallel (1.19.1)
50
- parser (2.7.1.0)
51
- ast (~> 2.4.0)
52
- public_suffix (4.0.4)
51
+ parallel (1.19.2)
52
+ parser (2.7.1.4)
53
+ ast (~> 2.4.1)
54
+ public_suffix (4.0.5)
53
55
  rainbow (3.0.0)
54
56
  rake (13.0.1)
57
+ rdoc (6.2.1)
58
+ regexp_parser (1.7.1)
55
59
  rexml (3.2.4)
56
- rubocop (0.81.0)
57
- jaro_winkler (~> 1.5.1)
60
+ rubocop (0.89.1)
58
61
  parallel (~> 1.10)
59
- parser (>= 2.7.0.1)
62
+ parser (>= 2.7.1.1)
60
63
  rainbow (>= 2.2.2, < 4.0)
64
+ regexp_parser (>= 1.7)
61
65
  rexml
66
+ rubocop-ast (>= 0.3.0, < 1.0)
62
67
  ruby-progressbar (~> 1.7)
63
68
  unicode-display_width (>= 1.4.0, < 2.0)
69
+ rubocop-ast (0.3.0)
70
+ parser (>= 2.7.1.4)
64
71
  ruby-progressbar (1.10.1)
65
72
  ruby-vips (2.0.17)
66
73
  ffi (~> 1.9)
@@ -75,21 +82,21 @@ GEM
75
82
  tzinfo (1.2.7)
76
83
  thread_safe (~> 0.1)
77
84
  unicode-display_width (1.7.0)
78
- zeitwerk (2.3.0)
85
+ zeitwerk (2.4.0)
79
86
 
80
87
  PLATFORMS
81
- ruby
82
88
  x64-mingw32
83
89
 
84
90
  DEPENDENCIES
85
91
  carrierwave (>= 2.0.0.rc, < 3.0)
86
92
  faraday (~> 0.17.1)
87
93
  jekyll-github-pages-gem!
88
- kramdown
94
+ kramdown (~> 2.3.0)
89
95
  minitest
90
96
  mocha
91
97
  octokit (~> 4.18)
92
98
  rake
99
+ rdoc
93
100
  rubocop (~> 0.71)
94
101
  simplecov
95
102
 
data/README.md CHANGED
@@ -9,8 +9,17 @@
9
9
  Our git flow process is typical--we have a master branch that gets released to the public, and feature branches for individual tasks. We don't have a development branch yet since this isn't used in production yet.
10
10
  If you have questions on how to contribute, please contact admin@msoe-sse.com or msoe.sg.hosting@gmail.com and we will get back to you at our earliest convenience.
11
11
 
12
+ ## Generating HTML Documentation
13
+ To generate HTML documentation for the Gem run the command `rake rdoc` and the HTML will then be available in the `html/` directory in the project.
14
+
12
15
  ## Continuous Integration
13
16
  There are checks that will be performed whenever Pull Requests are opened. To save time on the build server, please run the tests locally to check for errors that will occur in the CI builds.
14
17
 
15
- 1. To run [Rubocop](https://github.com/ashmaroli/rubocop-jekyll), run the command `bundle exec rubocop`
18
+ 1. To run [Rubocop](https://github.com/ashmaroli/rubocop-jekyll), run the command `bundle exec rubocop`. Note the command `bundle exec rubocop -a` will attempt to automatically fix any offenses found by rubocop but some still need to be resolved manually.
16
19
  2. To run all unit tests, run the command `rake`
20
+
21
+ ## Releasing the Gem
22
+ When the gem is released it's deployed to a https://rubygems.org project. The SSE webmaster controls the rubygems project and will handle releasing the gem to rubygems. The following commands below are used to release the gem if you have permissions to the rubygems project.
23
+
24
+ 1. `gem build jekyll_github_pages`
25
+ 2. `gem push jekyll-github-pages-gem-<VERSION>.gem`
data/Rakefile CHANGED
@@ -1,9 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rake/testtask'
4
+ require 'rdoc/task'
4
5
 
5
6
  task default: 'test'
6
7
 
7
8
  Rake::TestTask.new do |t|
8
9
  t.test_files = FileList['tests/**/*_test.rb']
9
10
  end
11
+
12
+ RDoc::Task.new do |rdoc|
13
+ rdoc.rdoc_files.include('lib/**/*.rb')
14
+ end
@@ -2,10 +2,14 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'jekyll-github-pages-gem'
5
- s.version = '1.0.0'
5
+ s.version = '1.1.3'
6
6
  s.summary = 'A gem that uses the github API to make edits with a jekyll blog'
7
7
  s.files = Dir['*', 'lib/**/*']
8
8
  s.require_paths = ['lib']
9
9
  s.licenses = ['MIT']
10
10
  s.authors = ['MSOE SSE Web Team']
11
+ s.add_runtime_dependency('carrierwave', '>= 2.0.0.rc', '< 3.0')
12
+ s.add_runtime_dependency('kramdown', '~> 2.3.0')
13
+ s.add_runtime_dependency('octokit', '~> 4.18')
14
+ s.required_ruby_version = '>= 2.5.1'
11
15
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kramdown'
4
+
5
+ module Factories
6
+ ##
7
+ # The base class for all jekyll factories
8
+ class BaseFactory
9
+ protected
10
+
11
+ def fix_header_syntax(text)
12
+ document = Kramdown::Document.new(text)
13
+ header_elements = document.root.children.select { |x| x.type == :header }
14
+ lines = text.split("\n")
15
+ lines = lines.map do |line|
16
+ if header_elements.any? { |x| line.include? x.options[:raw_text] }
17
+ # This regex matches the line into 2 groups with the first group being the repeating #
18
+ # characters and the beginning of the string and the second group being the rest of the string
19
+ line_match = line.match(/(#*)(.*)/)
20
+ line = "#{line_match.captures.first} #{line_match.captures.last.strip}"
21
+ else
22
+ line.delete("\r\n")
23
+ end
24
+ end
25
+ lines.join("\r\n")
26
+ end
27
+
28
+ def add_line_break_to_markdown_if_necessary(markdown)
29
+ lines = markdown.split("\n")
30
+ # The regular expression in the if statement looks for a markdown reference to a link like
31
+ # [logo]: https://ieeextreme.org/wp-content/uploads/2019/05/Xtreme_colour-e1557478323964.png
32
+ # If a post starts with that reference in jekyll followed by an image using that reference
33
+ # the line below will be interperted as a paragraph tag instead of an image tag. To fix that
34
+ # we add a line break to the start of the markdown.
35
+ return "\r\n#{markdown}" if lines.first&.match?(/\[(.*)\]: (.*)/)
36
+
37
+ markdown
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../models/page'
4
+
5
+ module Factories
6
+ ##
7
+ # This class is a factory for parsing page text and creating a correseponding page model
8
+ class PageFactory < BaseFactory
9
+ ##
10
+ # This method parses markdown in a page a returns a page model
11
+ #
12
+ # Params:
13
+ # +page_contents+::markdown in a given page
14
+ # +github_ref+::a sha for a ref indicating the head of a branch a page is pushed to on the GitHub server
15
+ # +pull_request_url+::a url to the pull request with the branch the pull request is pushed to on the GitHub server
16
+ def create_page(page_contents, github_ref, pull_request_url)
17
+ create_page_model(page_contents, github_ref, pull_request_url) if !page_contents.nil? && page_contents.is_a?(String)
18
+ end
19
+
20
+ ##
21
+ # This method takes parameters for a given page and formats them
22
+ # as a valid page for a Jekyll website
23
+ #
24
+ # Params:
25
+ # +text+:: the required markdown contents of the post
26
+ # +title+:: the required title of the post
27
+ # +permalink+:: the link to the page on a Jekyll website (e.g /about)
28
+ def create_jekyll_page_text(text, title, permalink)
29
+ header_converted_text = fix_header_syntax(text)
30
+ header_converted_text = add_line_break_to_markdown_if_necessary(header_converted_text)
31
+
32
+ %(---
33
+ layout: page
34
+ title: #{title}
35
+ permalink: #{permalink}
36
+ ---
37
+ #{header_converted_text})
38
+ end
39
+
40
+ private
41
+
42
+ def create_page_model(page_contents, github_ref, pull_request_url)
43
+ result = Page.new
44
+
45
+ result.github_ref = github_ref
46
+ result.pull_request_url = pull_request_url
47
+
48
+ # What this regular expression does is it matches three groups
49
+ # The first group represents the header of the page which appears
50
+ # between the two --- lines. The second group is for helping capture newline characters
51
+ # correctly and the third group is the actual page contents
52
+ match_obj = page_contents.match(/---(.*)---(\r\n|\r|\n)(.*)/m)
53
+ header = match_obj.captures[0]
54
+ parse_page_header(header, result)
55
+ result.contents = match_obj.captures[2]
56
+
57
+ result
58
+ end
59
+
60
+ def parse_page_header(header, page_model)
61
+ # The following regular expressions in this method look for specific properities
62
+ # located in the post header.
63
+ page_model.title = header.match(/title:\s*(.*)(\r\n|\r|\n)/).captures.first
64
+ page_model.permalink = header.match(/permalink:\s*(.*)(\r\n|\r|\n)/).captures.first
65
+ end
66
+ end
67
+ end
@@ -5,7 +5,7 @@ require_relative '../models/post'
5
5
  module Factories
6
6
  ##
7
7
  # This class is a factory for parsing post text and creating a correseponding post model
8
- class PostFactory
8
+ class PostFactory < BaseFactory
9
9
  LEAD = '{: .lead}'
10
10
  BREAK = '<!–-break-–>'
11
11
 
@@ -23,6 +23,50 @@ module Factories
23
23
  create_post_model(post_contents, file_path, ref) if !post_contents.nil? && post_contents.is_a?(String)
24
24
  end
25
25
 
26
+ ##
27
+ # This method takes parameters for a given post and formats them
28
+ # as a valid post for a Jekyll website
29
+ #
30
+ # Params:
31
+ # +text+:: the required markdown contents of the post
32
+ # +author+:: the required author of the post
33
+ # +title+:: the required title of the post
34
+ # +tags+:: optional tags specific to the post, defaults to nil
35
+ # +overlay+:: the optional overlay color of the post, defaults to nil
36
+ # +hero+:: a link to an optional background image for a post, defaults to nil
37
+ # +set_published_property+::an optional flag to set the published: true property for a post, defaults to false
38
+ # +append_lead_break_section+::an optional flag indicating whether to append to lead break section to a post, default to false
39
+ def create_jekyll_post_text(text, author, title, tags = nil, overlay = nil,
40
+ hero = nil, set_published_property = false, append_lead_break_section = false)
41
+ header_converted_text = fix_header_syntax(text)
42
+ header_converted_text = add_line_break_to_markdown_if_necessary(header_converted_text)
43
+
44
+ parsed_tags = nil
45
+ parsed_tags = format_tags(tags) if tags
46
+
47
+ tag_section = %(tags:
48
+ #{parsed_tags})
49
+
50
+ lead_break_section = "{: .lead}\r\n<!–-break-–>"
51
+
52
+ hero_to_use = hero
53
+ hero_to_use = DEFAULT_HERO if hero_to_use&.empty?
54
+ result = %(---
55
+ layout: post
56
+ title: #{title}
57
+ author: #{author}\r\n)
58
+
59
+ result += "#{tag_section}\r\n" unless !parsed_tags || parsed_tags.empty?
60
+ result += "hero: #{hero_to_use}\n" if hero_to_use
61
+ result += "overlay: #{overlay}\n" if overlay
62
+ result += "published: true\n" if set_published_property
63
+ result += "---\n"
64
+ result += "#{lead_break_section}\n" if append_lead_break_section
65
+ result += header_converted_text
66
+
67
+ result
68
+ end
69
+
26
70
  private
27
71
 
28
72
  def parse_tags(header)
@@ -34,6 +78,16 @@ module Factories
34
78
  result.join(', ')
35
79
  end
36
80
 
81
+ def format_tags(tags)
82
+ tag_array = tags.split(',')
83
+ result = ''
84
+ tag_array.each do |tag|
85
+ result += " - #{tag.strip}"
86
+ result += "\r\n" if tag != tag_array.last
87
+ end
88
+ result
89
+ end
90
+
37
91
  def create_post_model(post_contents, file_path, ref)
38
92
  result = Post.new
39
93
 
@@ -1,19 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Third Party Dependencies
4
- require 'carrierwave'
4
+ # require 'carrierwave'
5
5
 
6
6
  # Source Files
7
+ require 'factories/base_factory'
7
8
  require 'factories/post_factory'
8
- require 'services/post_services/base_post_service'
9
- require 'services/post_services/post_creation_service'
10
- require 'services/post_services/post_editing_service'
11
- require 'services/post_services/post_pull_request_editing_service'
12
- require 'services/github_service'
9
+ require 'factories/page_factory'
13
10
 
11
+ require 'services/base_editing_service'
12
+ require 'services/github_service'
14
13
  require 'services/kramdown_service'
14
+ require 'services/page_service'
15
+ require 'services/post_service'
15
16
 
17
+ require 'models/page'
16
18
  require 'models/post'
17
19
  require 'models/post_image_manager'
18
20
 
19
- require 'uploaders/post_image_uploader'
21
+ # require 'uploaders/post_image_uploader'
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # An object repsenting a page on a Jekyll website
5
+ class Page
6
+ attr_accessor :title
7
+ attr_accessor :permalink
8
+ attr_accessor :contents
9
+ # The GitHub ref the page's markdown is at. This is used to indicate
10
+ # whether a page is in PR or not
11
+ attr_accessor :github_ref
12
+ attr_accessor :pull_request_url
13
+ end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'singleton'
4
4
 
5
+ # TODO: This will eventually go away once carrierwave is removed
6
+
5
7
  ##
6
8
  # A singleton class for managing all image attachments for a post
7
9
  class PostImageManager
@@ -26,10 +28,10 @@ class PostImageManager
26
28
  # Params:
27
29
  # +file+:: A ActionDispatch::Http::UploadedFile object containing the file to be used in a post
28
30
  def add_file(file)
29
- uploader_to_add = PostImageUploader.new
30
- uploader_to_add.cache!(file)
31
- @uploaders.delete_if { |x| x.filename == file.original_filename }
32
- @uploaders << uploader_to_add
31
+ # uploader_to_add = PostImageUploader.new
32
+ # uploader_to_add.cache!(file)
33
+ # @uploaders.delete_if { |x| x.filename == file.original_filename }
34
+ # @uploaders << uploader_to_add
33
35
  end
34
36
 
35
37
  ##
@@ -38,21 +40,21 @@ class PostImageManager
38
40
  # Params:
39
41
  # +downloaded_image+:: A PostImage object representing the downloaded image
40
42
  def add_downloaded_image(downloaded_image)
41
- @downloaded_images << downloaded_image
43
+ # @downloaded_images << downloaded_image
42
44
  end
43
45
 
44
46
  ##
45
47
  # Clears the manager of all currently exisiting image uploaders and delete's their cache directories.
46
48
  # Also clears the manager of all of the downloaded images
47
- def clear(_root_dir)
48
- @uploaders.each do |uploader|
49
- full_preview_path = "#{@root_dir}/public/uploads/tmp/#{uploader.preview.cache_name}"
50
- cache_dir = File.expand_path('..', full_preview_path)
51
- uploader.remove!
52
- Dir.delete(cache_dir)
53
- end
54
-
55
- @uploaders.clear
56
- @downloaded_images.clear
49
+ def clear
50
+ # @uploaders.each do |uploader|
51
+ # full_preview_path = "#{@root_dir}/public/uploads/tmp/#{uploader.preview.cache_name}"
52
+ # cache_dir = File.expand_path('..', full_preview_path)
53
+ # uploader.remove!
54
+ # Dir.delete(cache_dir)
55
+ # end
56
+
57
+ # @uploaders.clear
58
+ # @downloaded_images.clear
57
59
  end
58
60
  end