jekyll-spaceship 0.4.2 → 0.5.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae6d96db2dd9498238ac13344b4b5f57bae9128792f0ecfab4c21e68e165f1d8
4
- data.tar.gz: f2d39600125fb3775285a6d1851f9d9549dc24ae68fcaec042d8c487356e6bb2
3
+ metadata.gz: d338b2284aa2d2e49850cc250cd9a3c989dc86416b0376cab582d83fa7394847
4
+ data.tar.gz: d620cda630210a123d39f2f99c8148da7b005b079183139baa9844acdc6bc46a
5
5
  SHA512:
6
- metadata.gz: 3755de40d7d23166ee87a215530517732ae0589fe7c30eb080ec06c8586f99d3e4899919511352b2e21185616b39768fe0067b8e12665d33a9243ca7fcd8768b
7
- data.tar.gz: a1d8018a105dc552493e1590ad20b1902bdbf81e20d018cbe5af0e80fa7b7f83522bf20f7f9d2a5463286f8421c54a414d9152233164f99149548bb9c411a6ea
6
+ metadata.gz: c9273181303043d1db856c988f8066c507d6918716f96cab4119bd6a451184fda4b48352d1890e8b91e65ee483fc9467fb9d5e1e731278e8ce0d7b5c18e2483c
7
+ data.tar.gz: dd0fbf8dd8c7f5300ee6940195fb8dca89c25623a39887e57bad224fda02bdd751e9779e650d5c1fc0b10e0b81386f34fe38f08681e0435765124bae02e0e4ea
@@ -0,0 +1,38 @@
1
+ version: "2"
2
+ checks:
3
+ argument-count:
4
+ enabled: true
5
+ config:
6
+ threshold: 5
7
+ file-lines:
8
+ enabled: true
9
+ config:
10
+ threshold: 300
11
+ method-complexity:
12
+ enabled: true
13
+ config:
14
+ threshold: 15
15
+ method-count:
16
+ enabled: true
17
+ config:
18
+ threshold: 50
19
+ method-lines:
20
+ enabled: true
21
+ config:
22
+ threshold: 30
23
+ plugins:
24
+ fixme:
25
+ enabled: false
26
+
27
+ exclude_patterns:
28
+ - "*.*"
29
+ - ".*"
30
+
31
+ - Gemfile
32
+ - LICENSE.txt
33
+ - Rakefile
34
+
35
+ - rake/
36
+ - script/
37
+ - spec/
38
+ - test/
@@ -0,0 +1,12 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
+ patreon: jeffreytse
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: jeffreytse
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: jeffreytse
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
data/README.md CHANGED
@@ -1,11 +1,93 @@
1
- # jekyll-spaceship
1
+ <h1 align="center">
2
+ <a href="https://github.com/jeffreytse/jekyll-spaceship">
3
+ <img alt="spaceship →~ jekyll" src="https://raw.githubusercontent.com/jeffreytse/jekyll-spaceship/master/logos/jekyll-spaceship-logo.png" width="400">
4
+ </a>
5
+ <br> 🚀 Jekyll Spaceship 🚀 <br>
6
+ </h1>
2
7
 
3
- [![Build Status](https://travis-ci.org/jeffreytse/jekyll-spaceship.svg?branch=master)](https://travis-ci.org/jeffreytse/jekyll-spaceship)
4
- [![Gem Version](https://badge.fury.io/rb/jekyll-spaceship.svg)](http://badge.fury.io/rb/jekyll-spaceship)
5
- [![Code Climate](https://codeclimate.com/github/jeffreytse/jekyll-spaceship/badges/gpa.svg)](https://codeclimate.com/github/jeffreytse/jekyll-spaceship)
6
- [![Test Coverage](https://api.codeclimate.com/v1/badges/cd56b207f327603662a1/test_coverage)](https://codeclimate.com/github/jeffreytse/jekyll-spaceship/test_coverage)
8
+ <h4 align="center">
9
+ <a href="https://jekyllrb.org" target="_blank"><code>Jekyll</code></a> plugin for Astronauts.
10
+ </h4>
11
+
12
+ <p align="center">
13
+
14
+ <a href="https://travis-ci.org/jeffreytse/jekyll-spaceship">
15
+ <img src="https://travis-ci.org/jeffreytse/jekyll-spaceship.svg?branch=master"
16
+ alt="CI Status" />
17
+ </a>
18
+
19
+ <a href="http://badge.fury.io/rb/jekyll-spaceship">
20
+ <img src="https://badge.fury.io/rb/jekyll-spaceship.svg"
21
+ alt="Gem Version" />
22
+ </a>
23
+
24
+ <a href="https://codeclimate.com/github/jeffreytse/jekyll-spaceship">
25
+ <img src="https://codeclimate.com/github/jeffreytse/jekyll-spaceship/badges/gpa.svg"
26
+ alt="Code Climate" />
27
+ </a>
28
+
29
+ <a href="https://codeclimate.com/github/jeffreytse/jekyll-spaceship/test_coverage">
30
+ <img src="https://api.codeclimate.com/v1/badges/cd56b207f327603662a1/test_coverage"
31
+ alt="Test Coverage" />
32
+ </a>
33
+
34
+ <a href="https://github.com/jeffreytse/jekyll-spaceship/blob/master/LICENSE.txt">
35
+ <img src="https://img.shields.io/badge/License-MIT-brightgreen.svg"
36
+ alt="License" />
37
+ </a>
38
+
39
+ <a href="http://badge.fury.io/rb/jekyll-spaceship">
40
+ <img src="https://img.shields.io/gem/dt/jekyll-spaceship"
41
+ alt="Download Data" />
42
+ </a>
43
+
44
+ </p>
45
+
46
+ <p align="center">
47
+
48
+ <a href="https://liberapay.com/jeffreytse">
49
+ <img src="http://img.shields.io/liberapay/goal/jeffreytse.svg?logo=liberapay"
50
+ alt="Donate (Liberapay)" />
51
+ </a>
52
+
53
+ <a href="https://patreon.com/jeffreytse">
54
+ <img src="https://img.shields.io/badge/support-patreon-F96854.svg?style=flat-square"
55
+ alt="Donate (Patreon)" />
56
+ </a>
57
+
58
+ <a href="https://ko-fi.com/jeffreytse">
59
+ <img height="20" src="https://www.ko-fi.com/img/githubbutton_sm.svg"
60
+ alt="Donate (Ko-fi)" />
61
+ </a>
62
+
63
+ </p>
64
+
65
+ <div align="center">
66
+ <h4>
67
+ <a href="#requirements">Requirements</a> |
68
+ <a href="#installation">Install</a> |
69
+ <a href="#usage">Usage</a> |
70
+ <a href="#credits">Credits</a> |
71
+ <a href="#license">License</a>
72
+ </h4>
73
+ </div>
74
+
75
+ <div align="center">
76
+ <sub>Built with ❤︎ by
77
+ <a href="https://jeffreytse.net">jeffreytse</a> and
78
+ <a href="https://github.com/jeffreytse/jekyll-spaceship/graphs/contributors">contributors </a>
79
+ </div>
80
+ <br>
81
+
82
+
83
+ A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, emoji, youtube, vimeo, dailymotion, etc.
84
+
85
+ <p align="center">
86
+ <img alt="Jekyll Spaceship Demo" src="https://user-images.githubusercontent.com/9413601/82250463-15451780-997e-11ea-8809-f411586d9508.gif" alt="Donate (Ko-fi)" />
87
+ </p>
88
+
89
+ **💡 Tip:** I hope you enjoy using this plugin. If you like this project, **a little star** for it is your way make a clear statement: **My work is valued**. I would appreciate your support! _Thank you!_
7
90
 
8
- A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, youtube, etc.
9
91
 
10
92
  ## Table of Contents
11
93
 
@@ -19,6 +101,8 @@ A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, youtu
19
101
  - [1.4 Cell Alignment](#cell-alignment)
20
102
  - [1.5 Cell Markdown](#cell-markdown)
21
103
  - [2. MathJax Usage](#2-mathjax-usage)
104
+ - [2.1 Performance Optimization](#21-performance-optimization)
105
+ - [2.2 How to use?](#22-how-to-use)
22
106
  - [3. PlantUML Usage](#3-plantuml-usage)
23
107
  - [4. Video Usage](#4-video-usage)
24
108
  - [4.1 Youtube Usage](#youtube-usage)
@@ -27,6 +111,7 @@ A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, youtu
27
111
  - [5. Hybrid HTML with Markdown](#5-hybrid-html-with-markdown)
28
112
  - [6. Markdown Polyfill](#6-markdown-polyfill)
29
113
  - [6.1 Escape Ordered List](#escape-ordered-list)
114
+ - [7. Emoji Usage](#7-emoji-usage)
30
115
  - [Credits](#credits)
31
116
  - [Contributing](#contributing)
32
117
  - [License](#license)
@@ -50,6 +135,8 @@ plugins:
50
135
  - jekyll-spaceship
51
136
  ```
52
137
 
138
+ **💡 Tip:** Note that GitHub Pages runs in `safe` mode and only allows [a set of whitelisted plugins](https://pages.github.com/versions/). To use the gem in GitHub Pages, you need to build locally or use CI (e.g. [travis](https://travis-ci.org/), [github workflow](https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow)) and deploy to your `gh-pages` branch. [Click here for more information.](https://jekyllrb.com/docs/continuous-integration/github-actions/)
139
+
53
140
  ## Usage
54
141
 
55
142
  ### 1. Table Usage
@@ -384,7 +471,7 @@ Rowspan is 4
384
471
 
385
472
  [MathJax](http://www.mathjax.org/) is an open-source JavaScript display engine for LaTeX, MathML, and AsciiMath notation that works in all modern browsers.
386
473
 
387
- **Some of the main features of MathJax include:**
474
+ Some of the main features of MathJax include:
388
475
 
389
476
  - High-quality display of LaTeX, MathML, and AsciiMath notation in HTML pages
390
477
  - Supported in most browsers with no plug-ins, extra fonts, or special
@@ -394,6 +481,12 @@ Rowspan is 4
394
481
  advanced functionality
395
482
  - Powerful API for integration with other web applications
396
483
 
484
+ #### 2.1 Performance optimization
485
+
486
+ At building stage, the MathJax engine script will be added by automatically checking whether there is a math expression in the page, this feature can help you improve the page performance on loading speed.
487
+
488
+ #### 2.2 How to use?
489
+
397
490
  Put your math expression within \$...\$
398
491
 
399
492
  ```markdown
@@ -472,7 +565,7 @@ the link as below:
472
565
  ```
473
566
 
474
567
  ```markdown
475
- ![](https://www.dailymotion.com/video/x7tfyq3?width=100%&height=400)
568
+ ![](https://www.dailymotion.com/video/x7tfyq3?width=100%&height=400&autoplay=1)
476
569
  ```
477
570
 
478
571
  #### Youtube Usage
@@ -581,11 +674,27 @@ Escaped:
581
674
  10. List item Cafe.
582
675
  ```
583
676
 
677
+ ### 7. Emoji Usage
678
+ GitHub-flavored emoji images and names would allow emojifying content such as: it's raining :cat:s and :dog:s!
679
+
680
+ Noted that emoji images are served from the GitHub.com CDN, with a base URL of [https://github.githubassets.com](https://github.githubassets.com), which results in emoji image URLs like [https://github.githubassets.com/images/icons/emoji/unicode/1f604.png](https://github.githubassets.com/images/icons/emoji/unicode/1f604.png).
681
+
682
+ In any page or post, use emoji as you would normally, e.g.
683
+
684
+ ```
685
+ I give this plugin two :+1:!
686
+ ```
687
+
688
+ **Code above would be parsed as:**
689
+
690
+ I give this plugin two :+1:!
691
+
584
692
  ## Credits
585
693
 
586
694
  - [Jekyll](https://github.com/jekyll/jekyll) - A blog-aware static site generator in Ruby.
587
695
  - [MultiMarkdown](https://fletcher.github.io/MultiMarkdown-6) - Lightweight markup processor to produce HTML, LaTeX, and more.
588
696
  - [markdown-it-multimd-table](https://github.com/RedBug312/markdown-it-multimd-table) - Multimarkdown table syntax plugin for markdown-it markdown parser.
697
+ - [jmoji](https://github.com/jekyll/jemoji) - GitHub-flavored emoji plugin for Jekyll.
589
698
 
590
699
  ## Contributing
591
700
 
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.version = Jekyll::Spaceship::VERSION
10
10
  spec.authors = ["jeffreytse"]
11
11
  spec.email = ["jeffreytse.mail@gmail.com"]
12
- spec.summary = "A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, youtube, vimeo, dailymotion, etc."
12
+ spec.summary = "A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, emoji, youtube, vimeo, dailymotion, etc."
13
13
  spec.homepage = "https://github.com/jeffreytse/jekyll-spaceship"
14
14
  spec.license = "MIT"
15
15
 
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "jekyll", ">= 3.6", "< 5.0"
22
22
  spec.add_dependency "nokogiri", "~> 1.6"
23
+ spec.add_dependency "rainbow", "~> 3.0"
23
24
 
24
25
  spec.add_development_dependency "bundler"
25
26
  spec.add_development_dependency "rake", "~> 12.0"
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'jekyll-spaceship/cores/logger'
4
+ require 'jekyll-spaceship/cores/manager'
4
5
  require 'jekyll-spaceship/cores/processor'
5
6
  require 'jekyll-spaceship/cores/register'
6
7
 
@@ -11,4 +12,5 @@ module Jekyll::Spaceship
11
12
  Register.use 'plantuml-processor'
12
13
  Register.use 'polyfill-processor'
13
14
  Register.use 'video-processor'
15
+ Register.use 'emoji-processor'
14
16
  end
@@ -1,21 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'jekyll-spaceship/version'
4
+ require 'rainbow/refinement'
5
+
6
+ using Rainbow
4
7
 
5
8
  module Jekyll::Spaceship
6
9
  class Logger
10
+ def initialize(namespace)
11
+ @namespace = namespace
12
+ end
13
+
7
14
  def self.display_info
8
- self.log "Jekyll-Spaceship #{Jekyll::Spaceship::VERSION}"
9
- self.log 'A Jekyll plugin to provide powerful supports.'
10
- self.log 'https://github.com/jeffreytse/jekyll-spaceship'
15
+ self.log "🚀 Jekyll-Spaceship #{Jekyll::Spaceship::VERSION}"
16
+ self.log '🎉 A Jekyll plugin to provide powerful supports.'
17
+ self.log '👉 ' + 'https://github.com/jeffreytse/jekyll-spaceship'.underline
11
18
  end
12
19
 
13
20
  def self.log(content)
14
- self.output 'Jekyll Spaceship', content
21
+ self.output 'Jekyll Spaceship', content.bright
15
22
  end
16
23
 
17
24
  def self.output(title, content)
18
25
  puts "#{title.rjust(18)}: #{content}"
19
26
  end
27
+
28
+ def log(content)
29
+ if @namespace.nil?
30
+ self.class.log content
31
+ else
32
+ self.class.log "[#{@namespace}] #{content}"
33
+ end
34
+ end
20
35
  end
21
36
  end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nokogiri'
4
+ require __dir__ + '/type'
5
+
6
+ module Jekyll::Spaceship
7
+ class Manager
8
+ @@_hooks = {}
9
+ @@_processors = []
10
+
11
+ def self.add(processor)
12
+ # register for listening event
13
+ processor.registers.each do |_register|
14
+ container = _register.first
15
+ events = _register.last.uniq
16
+ events = events.select do |event|
17
+ next true if event.match(/^post/)
18
+ next !events.any?(event.to_s.gsub(/^pre/, 'post').to_sym)
19
+ end
20
+ events.each do |event|
21
+ self.hook container, event
22
+ end
23
+ end
24
+ @@_processors.push(processor)
25
+ @@_processors = @@_processors.sort { |a, b| b.priority <=> a.priority }
26
+ end
27
+
28
+ def self.hook(container, event, &block)
29
+ return if not is_hooked? container, event
30
+
31
+ handler = ->(page) {
32
+ self.dispatch page, container, event
33
+ block.call if block
34
+ }
35
+
36
+ if event.to_s.start_with?('after')
37
+ Jekyll::Hooks.register container, event do |page|
38
+ handler.call page
39
+ end
40
+ elsif event.to_s.start_with?('post')
41
+ Jekyll::Hooks.register container, event do |page|
42
+ handler.call page
43
+ end
44
+ # auto add pre-event
45
+ self.hook container, event.to_s.sub('post', 'pre').to_sym
46
+ elsif event.to_s.start_with?('pre')
47
+ Jekyll::Hooks.register container, event do |page|
48
+ handler.call page
49
+ end
50
+ end
51
+ end
52
+
53
+ def self.is_hooked?(container, event)
54
+ hook_name = "#{container}_#{event}".to_sym
55
+ return false if @@_hooks.has_key? hook_name
56
+ @@_hooks[hook_name] = true
57
+ end
58
+
59
+ def self.dispatch(page, container, event)
60
+ @@_processors.each do |processor|
61
+ processor.dispatch page, container, event
62
+ end
63
+ if event.to_s.start_with?('post') and Type.html? output_ext(page)
64
+ self.dispatch_html_block(page)
65
+ end
66
+ @@_processors.each do |processor|
67
+ processor.on_handled if processor.handled
68
+ end
69
+ end
70
+
71
+ def self.ext(page)
72
+ page.data['ext']
73
+ end
74
+
75
+ def self.output_ext(page)
76
+ page.url_placeholders[:output_ext]
77
+ end
78
+
79
+ def self.converter(page, name)
80
+ page.site.converters.each do |converter|
81
+ class_name = converter.class.to_s.downcase
82
+ return converter if class_name.end_with?(name.downcase)
83
+ end
84
+ end
85
+
86
+ def self.dispatch_html_block(page)
87
+ doc = Nokogiri::HTML(page.output)
88
+ doc.css('script').each do |node|
89
+ type = Type.html_block_type node['type']
90
+ content = node.content
91
+ next if type.nil?
92
+
93
+ # dispatch to on_handle_html_block
94
+ @@_processors.each do |processor|
95
+ next unless processor.process?
96
+ content = processor.on_handle_html_block content, type
97
+ # dispatch to type handlers
98
+ method = "on_handle_#{type}"
99
+ next unless processor.respond_to? method
100
+ content = processor.pre_exclude content
101
+ content = processor.send method, content
102
+ content = processor.after_exclude content
103
+ end
104
+
105
+ cvter = self.converter page, type
106
+ content = cvter.convert content unless cvter.nil?
107
+
108
+ # dispatch to on_handle_html
109
+ @@_processors.each do |processor|
110
+ next unless processor.process?
111
+ content = processor.on_handle_html content
112
+ end
113
+ node.replace Nokogiri::HTML.fragment content
114
+ end
115
+ page.output = doc.to_html
116
+ end
117
+ end
118
+ end
@@ -1,56 +1,46 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'nokogiri'
4
-
5
3
  module Jekyll::Spaceship
6
4
  class Processor
7
- @@_hooks = {}
8
- @@_registers = []
9
- @@_processers = []
10
- @@_exclusions = []
11
- @@_priority = nil
12
-
13
- attr_accessor :priority
14
- attr_accessor :page
15
- attr_accessor :handled
16
-
17
5
  DEFAULT_PRIORITY = 20
18
6
 
19
7
  PRIORITY_MAP = {
20
- :low => 10,
21
- :normal => 20,
22
- :high => 30,
8
+ :lowest => 0,
9
+ :low => 10,
10
+ :normal => 20,
11
+ :high => 30,
12
+ :highest => 40,
23
13
  }.freeze
24
14
 
25
- HTML_EXTENSIONS = %w(
26
- .html
27
- .xhtml
28
- .htm
29
- ).freeze
15
+ @@_registers = []
16
+ @@_exclusions = []
17
+ @@_priority = nil
30
18
 
31
- CSS_EXTENSIONS = %w(
32
- .css
33
- .scss
34
- ).freeze
19
+ attr_reader :page
20
+ attr_reader :logger
21
+ attr_reader :priority
22
+ attr_reader :registers
23
+ attr_reader :exclusions
24
+ attr_accessor :handled
35
25
 
36
- MD_EXTENSIONS = %w(
37
- .md
38
- .markdown
39
- ).freeze
26
+ def name
27
+ self.class.name.split('::').last
28
+ end
40
29
 
41
30
  def initialize()
42
31
  self.initialize_priority
43
32
  self.initialize_register
44
33
  self.initialize_exclusions
34
+ @logger = Logger.new(self.name)
45
35
  end
46
36
 
47
37
  def initialize_priority
48
- @@_priority = DEFAULT_PRIORITY if @@_priority.nil?
49
38
  @priority = @@_priority
39
+ unless @priority.nil? or @priority.is_a? Numeric
40
+ @priority = PRIORITY_MAP[@priority.to_sym]
41
+ end
42
+ @priority = DEFAULT_PRIORITY if @priority.nil?
50
43
  @@_priority = nil
51
-
52
- @@_processers.push(self)
53
- @@_processers = @@_processers.sort { |a, b| b.priority <=> a.priority }
54
44
  end
55
45
 
56
46
  def initialize_register
@@ -58,18 +48,7 @@ module Jekyll::Spaceship
58
48
  self.class.register :pages, :pre_render, :post_render
59
49
  self.class.register :posts, :pre_render, :post_render
60
50
  end
61
-
62
- @@_registers.each do |_register|
63
- container = _register.first
64
- events = _register.last.uniq
65
- events = events.select do |event|
66
- next true if event.match(/^post/)
67
- next !events.any?(event.to_s.gsub(/^pre/, 'post').to_sym)
68
- end
69
- events.each do |event|
70
- self.class.hook container, event
71
- end
72
- end
51
+ @registers = Array.new @@_registers
73
52
  @@_registers.clear
74
53
  end
75
54
 
@@ -77,165 +56,84 @@ module Jekyll::Spaceship
77
56
  if @@_exclusions.size.zero?
78
57
  self.class.exclude :code, :block_quotes
79
58
  end
80
- @_exclusions = @@_exclusions.uniq
59
+ @exclusions = @@_exclusions.uniq
81
60
  @@_exclusions.clear
82
61
  end
83
62
 
84
63
  def self.priority(value)
85
- value = value.to_sym
86
- if PRIORITY_MAP.has_key? value
87
- @@_priority = PRIORITY_MAP[value]
88
- elsif value.nil?
89
- @@_priority = DEFAULT_PRIORITY
90
- else
91
- @@_priority = value
92
- end
64
+ @@_priority = value.to_sym
93
65
  end
94
66
 
95
67
  def self.register(container, *events)
96
68
  @@_registers << [container, events]
97
69
  end
98
70
 
99
- def self.hook_register(container, event)
100
- hook_name = "#{container}_#{event}".to_sym
101
- return false if @@_hooks.has_key? hook_name
102
- @@_hooks[hook_name] = true
71
+ def self.exclude(*types)
72
+ @@_exclusions = types
103
73
  end
104
74
 
105
- def self.hook(container, event, &block)
106
- return if not hook_register container, event
75
+ def process?
76
+ Type.html?(output_ext) or Type.markdown?(ext)
77
+ end
107
78
 
108
- # define dispatch proc
109
- dispatch = ->(instance) {
110
- @@_processers.each do |processor|
111
- processor.page = instance
112
- processor.handled = false
113
- next if not processor.process?
114
- processor.dispatch container, event
115
- end
116
- if event.to_s.start_with?('post') and self.html? output_ext(instance)
117
- self.handle_html_block(instance)
118
- end
119
- @@_processers.each do |processor|
120
- processor.page = instance
121
- if processor.handled
122
- processor.on_handled
123
- end
124
- end
125
- block.call if block
126
- }
79
+ def ext
80
+ Manager.ext @page
81
+ end
127
82
 
128
- if event.to_s.start_with?('after')
129
- Jekyll::Hooks.register container, event do |instance|
130
- dispatch.call instance
131
- end
132
- elsif event.to_s.start_with?('post')
133
- Jekyll::Hooks.register container, event do |instance|
134
- dispatch.call instance
135
- end
83
+ def output_ext
84
+ Manager.output_ext @page
85
+ end
136
86
 
137
- # auto add pre-event
138
- register container, event.to_s.sub('post', 'pre').to_sym
139
- elsif event.to_s.start_with?('pre')
140
- Jekyll::Hooks.register container, event do |instance|
141
- dispatch.call instance
142
- end
143
- end
87
+ def converter(name)
88
+ Manager.converter @page, name
144
89
  end
145
90
 
146
- def dispatch(container, event)
91
+ def dispatch(page, container, event)
92
+ @page = page
93
+ @handled = false
94
+ return unless self.process?
147
95
  method = "on_#{container}_#{event}"
148
96
  self.send method, @page if self.respond_to? method
149
-
97
+ method = ''
150
98
  if event.to_s.start_with?('pre')
151
- if markdown? ext
99
+ if Type.markdown? ext
152
100
  method = 'on_handle_markdown'
153
- else
154
- method = ''
155
101
  end
156
-
157
102
  if self.respond_to? method
158
103
  @page.content = self.pre_exclude @page.content
159
104
  @page.content = self.send method, @page.content
160
105
  @page.content = self.after_exclude @page.content
161
106
  end
162
107
  else
163
- if html? output_ext
108
+ if Type.html? output_ext
164
109
  method = 'on_handle_html'
165
110
  elsif css? output_ext
166
111
  method = 'on_handle_css'
167
- else
168
- method = ''
169
112
  end
170
-
171
113
  if self.respond_to? method
172
114
  @page.output = self.send method, @page.output
173
115
  end
174
116
  end
175
117
  end
176
118
 
177
- def self.exclude(*types)
178
- @@_exclusions = types
179
- end
180
-
181
- def html?(_ext)
182
- self.class.html? _ext
183
- end
184
-
185
- def css?(_ext)
186
- self.class.css? _ext
187
- end
188
-
189
- def markdown?(_ext)
190
- self.class.markdown? _ext
191
- end
192
-
193
- def self.html?(_ext)
194
- HTML_EXTENSIONS.include?(_ext)
195
- end
196
-
197
- def self.css?(_ext)
198
- CSS_EXTENSIONS.include?(_ext)
199
- end
200
-
201
- def self.markdown?(_ext)
202
- MD_EXTENSIONS.include?(_ext)
203
- end
204
-
205
- def converter(name)
206
- self.class.converter(@page, name)
207
- end
208
-
209
- def self.converter(instance, name)
210
- instance.site.converters.each do |converter|
211
- class_name = converter.class.to_s.downcase
212
- return converter if class_name.end_with?(name.downcase)
213
- end
214
- end
215
-
216
- def ext
217
- self.class.ext @page
218
- end
219
-
220
- def output_ext
221
- self.class.output_ext @page
222
- end
223
-
224
- def self.ext(instance)
225
- instance.data['ext']
119
+ def on_handle_html_block(content, type)
120
+ # default handle method
121
+ content
226
122
  end
227
123
 
228
- def self.output_ext(instance)
229
- instance.url_placeholders[:output_ext]
124
+ def on_handle_html(content)
125
+ # default handle method
126
+ content
230
127
  end
231
128
 
232
- def process?
233
- html?(output_ext) or markdown?(ext)
129
+ def on_handled
130
+ file = page.path.gsub(/.*_posts\//, '')
131
+ logger.log file
234
132
  end
235
133
 
236
134
  def pre_exclude(content)
237
- @_exclusion_store = []
238
- @_exclusions.each do |type|
135
+ @exclusion_store = []
136
+ @exclusions.each do |type|
239
137
  regex = nil
240
138
  if type == :code
241
139
  regex = /(`{3}\s*(\w*)((?:.|\n)*?)`{3})/
@@ -243,83 +141,22 @@ module Jekyll::Spaceship
243
141
  next if regex.nil?
244
142
  content.scan(regex) do |match_data|
245
143
  match = match_data[0]
246
- id = @_exclusion_store.size
144
+ id = @exclusion_store.size
247
145
  content = content.gsub(match, "[//]: JEKYLL_EXCLUDE_##{id}")
248
- @_exclusion_store.push match
146
+ @exclusion_store.push match
249
147
  end
250
148
  end
251
149
  content
252
150
  end
253
151
 
254
152
  def after_exclude(content)
255
- while @_exclusion_store.size > 0
256
- match = @_exclusion_store.pop
257
- id = @_exclusion_store.size
153
+ while @exclusion_store.size > 0
154
+ match = @exclusion_store.pop
155
+ id = @exclusion_store.size
258
156
  content = content.gsub("[//]: JEKYLL_EXCLUDE_##{id}", match)
259
157
  end
260
- @_exclusion_store = []
158
+ @exclusion_store = []
261
159
  content
262
160
  end
263
-
264
- def on_handled
265
- processor = self.class.name.split('::').last
266
- file = page.path.gsub(/.*_posts\//, '')
267
- Logger.log "[#{processor}] #{file}"
268
- end
269
-
270
- def self.handle_html_block(instance)
271
- doc = Nokogiri::HTML(instance.output)
272
-
273
- doc.css('script').each do |node|
274
- blk_type = node['type']
275
- blk_content = node.content
276
-
277
- cvter = nil
278
- method = ''
279
- block_method = 'on_handle_html_block'
280
-
281
- case blk_type
282
- when 'text/markdown'
283
- method = 'on_handle_markdown'
284
- cvter = self.converter(instance, 'markdown')
285
- end
286
-
287
- @@_processers.each do |processor|
288
- processor.page = instance
289
- next if not processor.process?
290
-
291
- # dispatch to on_handle_html_block
292
- if processor.respond_to? block_method
293
- blk_content = processor.send block_method blk_content, blk_type
294
- end
295
-
296
- # dispatch to other handlers
297
- if processor.respond_to? method
298
- blk_content = processor.pre_exclude blk_content
299
- blk_content = processor.send method, blk_content
300
- blk_content = processor.after_exclude blk_content
301
- end
302
- end
303
-
304
- if not cvter.nil?
305
- blk_content = cvter.convert blk_content
306
- end
307
-
308
- next if method == ''
309
-
310
- method = 'on_handle_html'
311
- @@_processers.each do |processor|
312
- processor.page = instance
313
- next if not processor.process?
314
- if processor.respond_to? method
315
- blk_content = processor.send method, blk_content
316
- end
317
- end
318
-
319
- node.replace Nokogiri::HTML.fragment(blk_content)
320
- end
321
-
322
- instance.output = doc.to_html
323
- end
324
161
  end
325
162
  end