jekyll-openmoji 0.0.2 → 0.0.3

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: 36945bfce6dc74cce5c09c8c0e41742da5592d89f1ce874539b665cdbd70ab5a
4
- data.tar.gz: 66c1f4a316c92baacabf1c5f7a0a9ea98c960df85729f94c0914eed62db825fb
3
+ metadata.gz: feb8c2e3b8485082d627573c5c5ba37689b7d3920b6a58be5235d268dd1565d7
4
+ data.tar.gz: 8b4997c7635d5e6362461f5880edeebba6fcbf53528e0f3e89017e180a6e598c
5
5
  SHA512:
6
- metadata.gz: 7dcd86c1832240e23562d5facce50a39dea5cb6e8d991b29c936bbee6cb45935081361ac6798421557df913d9f2e5863cc8529e81cf7eec6666da9f89c8d05c6
7
- data.tar.gz: b0194288ab62cfab9028586cbd19fc83c3f3c39fcae4b24e11ca6f6065c5ca4bb6d88ae8e3034573d3a262bdefdd1640f793150fbe4b8edfd20ec67720d0a0c7
6
+ metadata.gz: '0491f04b3255a8f48cfd677864693b044f292b003166885743355cab412f0e458ce0bc4dc901a11b34e7a134ca8ee2dffc8fa5accea25f86d23b2f42521723d0'
7
+ data.tar.gz: 4c8573632bb07250738f9adbb17fa4390d97f9c906cbb6ea0195cfe472105fe2da57a92176b75542ae8e9ccfa4cf44cdf3d2f7550c937bea65faa3d7072c23e0
@@ -0,0 +1,148 @@
1
+ # Created by https://www.gitignore.io/api/ruby,jekyll,rubymine
2
+ # Edit at https://www.gitignore.io/?templates=ruby,jekyll,rubymine
3
+
4
+ ### Jekyll ###
5
+ _site/
6
+ .sass-cache/
7
+ .jekyll-cache/
8
+ .jekyll-metadata
9
+
10
+ ### Ruby ###
11
+ Gemfile.lock
12
+ *.gem
13
+ *.rbc
14
+ /.config
15
+ /coverage/
16
+ /InstalledFiles
17
+ /pkg/
18
+ /spec/reports/
19
+ /spec/examples.txt
20
+ /test/tmp/
21
+ /test/version_tmp/
22
+ /tmp/
23
+ /.rakeTasks
24
+
25
+ # Used by dotenv library to load environment variables.
26
+ # .env
27
+
28
+ # Ignore Byebug command history file.
29
+ .byebug_history
30
+
31
+ ## Specific to RubyMotion:
32
+ .dat*
33
+ .repl_history
34
+ build/
35
+ *.bridgesupport
36
+ build-iPhoneOS/
37
+ build-iPhoneSimulator/
38
+
39
+ ## Specific to RubyMotion (use of CocoaPods):
40
+ #
41
+ # We recommend against adding the Pods directory to your .gitignore. However
42
+ # you should judge for yourself, the pros and cons are mentioned at:
43
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
44
+ # vendor/Pods/
45
+
46
+ ## Documentation cache and generated files:
47
+ /.yardoc/
48
+ /_yardoc/
49
+ /doc/
50
+ /rdoc/
51
+
52
+ ## Environment normalization:
53
+ /.bundle/
54
+ /vendor/bundle
55
+ /lib/bundler/man/
56
+
57
+ # for a library or gem, you might want to ignore these files since the code is
58
+ # intended to run in multiple environments; otherwise, check them in:
59
+ # Gemfile.lock
60
+ # .ruby-version
61
+ # .ruby-gemset
62
+
63
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
64
+ .rvmrc
65
+
66
+ ### RubyMine ###
67
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
68
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
69
+
70
+ # User-specific stuff
71
+ /.idea/
72
+ .idea/**/workspace.xml
73
+ .idea/**/tasks.xml
74
+ .idea/**/usage.statistics.xml
75
+ .idea/**/dictionaries
76
+ .idea/**/shelf
77
+
78
+ # Generated files
79
+ .idea/**/contentModel.xml
80
+
81
+ # Sensitive or high-churn files
82
+ .idea/**/dataSources/
83
+ .idea/**/dataSources.ids
84
+ .idea/**/dataSources.local.xml
85
+ .idea/**/sqlDataSources.xml
86
+ .idea/**/dynamic.xml
87
+ .idea/**/uiDesigner.xml
88
+ .idea/**/dbnavigator.xml
89
+
90
+ # Gradle
91
+ .idea/**/gradle.xml
92
+ .idea/**/libraries
93
+
94
+ # Gradle and Maven with auto-import
95
+ # When using Gradle or Maven with auto-import, you should exclude module files,
96
+ # since they will be recreated, and may cause churn. Uncomment if using
97
+ # auto-import.
98
+ # .idea/modules.xml
99
+ # .idea/*.iml
100
+ # .idea/modules
101
+ # *.iml
102
+ # *.ipr
103
+
104
+ # CMake
105
+ cmake-build-*/
106
+
107
+ # Mongo Explorer plugin
108
+ .idea/**/mongoSettings.xml
109
+
110
+ # File-based project format
111
+ *.iws
112
+
113
+ # IntelliJ
114
+ out/
115
+
116
+ # mpeltonen/sbt-idea plugin
117
+ .idea_modules/
118
+
119
+ # JIRA plugin
120
+ atlassian-ide-plugin.xml
121
+
122
+ # Cursive Clojure plugin
123
+ .idea/replstate.xml
124
+
125
+ # Crashlytics plugin (for Android Studio and IntelliJ)
126
+ com_crashlytics_export_strings.xml
127
+ crashlytics.properties
128
+ crashlytics-build.properties
129
+ fabric.properties
130
+
131
+ # Editor-based Rest Client
132
+ .idea/httpRequests
133
+
134
+ # Android studio 3.1+ serialized cache file
135
+ .idea/caches/build_file_checksums.ser
136
+
137
+ ### RubyMine Patch ###
138
+ # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
139
+
140
+ # *.iml
141
+ # modules.xml
142
+ # .idea/misc.xml
143
+ # *.ipr
144
+
145
+ # Sonarlint plugin
146
+ .idea/sonarlint
147
+
148
+ # End of https://www.gitignore.io/api/ruby,jekyll,rubymine
@@ -0,0 +1,31 @@
1
+ stages:
2
+ - test
3
+ - deploy
4
+
5
+ default:
6
+ image: ruby:latest
7
+ cache:
8
+ paths:
9
+ - vendor/
10
+ before_script:
11
+ # upgrade bundler to latest version
12
+ - gem install bundler
13
+ # install required gems
14
+ - bundle install --path vendor
15
+
16
+ test:
17
+ stage: test
18
+ # before_script:
19
+ script:
20
+ - script/ci-test
21
+ only:
22
+ - master
23
+ - merge_requests
24
+
25
+ #deploy-gem:
26
+ # stage: deploy
27
+ # before_script:
28
+ # - chmod +x ./deploy-gem
29
+ # script: ./deploy-gem
30
+ # only:
31
+ # - master
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,10 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ require: rubocop-jekyll
4
+ inherit_gem:
5
+ rubocop-jekyll: .rubocop.yml
6
+
7
+ AllCops:
8
+ TargetRubyVersion: 2.3
9
+ Exclude:
10
+ - vendor/**/*
@@ -0,0 +1,25 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-12-06 11:59:49 +0100 using RuboCop version 0.61.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: CountComments, Max, ExcludedMethods.
11
+ # ExcludedMethods: refine
12
+ Metrics/BlockLength:
13
+ Exclude:
14
+ - "spec/jekyll-openmoji_spec.rb"
15
+
16
+ # Offense count: 1
17
+ # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
18
+ # URISchemes: http, https
19
+ Metrics/LineLength:
20
+ Exclude:
21
+ - "spec/jekyll-openmoji_spec.rb"
22
+
23
+ Metrics/AbcSize:
24
+ Exclude:
25
+ - "lib/jekyll-openmoji/plugin.rb"
@@ -0,0 +1,35 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - &latest_ruby 2.6
5
+ - 2.4
6
+ - 2.3
7
+ env:
8
+ - JEKYLL_VERSION="~> 3.8"
9
+ matrix:
10
+ include:
11
+ - # GitHub Pages
12
+ rvm: 2.5.3
13
+ env: GH_PAGES=true
14
+ - rvm: *latest_ruby
15
+ env: JEKYLL_VERSION=">= 4.0.0.pre.alpha1"
16
+
17
+ before_install:
18
+ - gem update --system
19
+ - gem install bundler
20
+ before_script: bundle update
21
+ script: script/ci-test
22
+ branches:
23
+ only:
24
+ - master
25
+ notifications:
26
+ irc:
27
+ on_success: change
28
+ on_failure: change
29
+ channels:
30
+ - irc.freenode.org#jekyll
31
+ template:
32
+ - '%{repository}#%{build_number} (%{branch}) %{message} %{build_url}'
33
+ email:
34
+ on_success: never
35
+ on_failure: never
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
@@ -0,0 +1,79 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to make participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies within all project spaces, and it also applies when
49
+ an individual is representing the project or its community in public spaces.
50
+ Examples of representing a project or community include using an official
51
+ project e-mail address, posting via an official social media account, or acting
52
+ as an appointed representative at an online or offline event. Representation of
53
+ a project may be further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at [MahdiBaghbani@protonmail.com][email]. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ [email]: mailto:MahdiBaghbani@protonmail.com
69
+
70
+ ## Attribution
71
+
72
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
73
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
74
+
75
+ [homepage]: https://www.contributor-covenant.org
76
+
77
+ For answers to common questions about this code of conduct, see
78
+ https://www.contributor-covenant.org/faq
79
+
@@ -0,0 +1,16 @@
1
+ ## Contribute to OpenMoji Jekyll Plugin
2
+
3
+ ### Quick start
4
+
5
+ 1. Open an issue about your feature request or bug report at the first place to discuss it before starting coding
6
+ 2. Fork this repo on GitLab
7
+ 3. Create a new branch e.g. my-awesome-new-feature
8
+ 4. Follow guidelines in commit messages
9
+ 5. Edit `CHANGELOG.md` file
10
+ 6. Run `script/test` to see if you didn't break anything
11
+ 7. Create a pull request on GitLab
12
+
13
+ ### Commit message guideline
14
+ In order to keep git logs clean and easy to understand for future development, please follow this
15
+ guideline:
16
+
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "github-pages" if ENV["GH_PAGES"]
8
+ gem "jekyll", ENV["JEKYLL_VERSION"] if ENV["JEKYLL_VERSION"]
File without changes
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ ## OpenMoji Support
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "jekyll-openmoji/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "jekyll-openmoji"
9
+ spec.version = Jekyll::Emoji::VERSION
10
+ spec.platform = Gem::Platform::RUBY
11
+ spec.authors = ["Mohammad Mahdi Baghbani Pourvahid"]
12
+ spec.email = "MahdiBaghbani@protonmail.com"
13
+ spec.homepage = "https://gitlab.com/Azadeh-Afzar/Web-Development/OpenMoji-Jekyll-Plugin"
14
+ spec.description = "%q{OpenMoji emoji pack plugin for Jekyll with a powerful configuration options
15
+ and support for various emoji image file sources and extensions}"
16
+ spec.summary = "OpenMoji emoji plugin for Jekyll"
17
+ spec.licenses = "GPL-3.0"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(images|script|spec)/!) }
20
+ spec.executables = spec.files.grep(%r!^bin/!) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r!^test/!)
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.required_ruby_version = ">= 2.3.0"
25
+
26
+ spec.add_dependency "html-pipeline", "~> 2.2"
27
+ spec.add_dependency "html-pipeline-negarmoji", "~> 0.0.4"
28
+ spec.add_dependency "jekyll", ">= 3.0", "< 5.0"
29
+ spec.add_dependency "negarmoji", "~> 0.1.1"
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "rake", "~> 12.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.add_development_dependency "rubocop-jekyll", "~> 0.4"
35
+ spec.add_development_dependency "simplecov", "~> 0.17.0"
36
+ end
@@ -1,141 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "jekyll"
4
- require "gemoji"
5
- require "negarmoji"
6
- require "html/pipeline"
7
-
8
- module Jekyll
9
- class Emoji
10
- OPENMOJI_ASSET_HOST_URL = "https://cdn.jsdelivr.net/gh/azadeh-afzar/OpenMoji-Jekyll-Plugin@latest"
11
- ASSET_PATH = "/images/color/svg"
12
- DEFAULT_DIR = "/emoji"
13
- FILE_NAME = "/:file_name"
14
- BODY_START_TAG = "<body"
15
- OPENING_BODY_TAG_REGEX = %r!<body(.*?)>\s*!m.freeze
16
-
17
- class << self
18
- def emojify(doc)
19
- return unless doc.output =~ HTML::Pipeline::EmojiFilter.emoji_pattern
20
-
21
- doc.output = if doc.output.include? BODY_START_TAG
22
- replace_document_body(doc)
23
- else
24
- src_root = emoji_src_root(doc.site.config)
25
- asset_path = emoji_asset_path(doc.site.config)
26
- filter_with_emoji(src_root, asset_path).call(doc.output)[:output].to_s
27
- end
28
- end
29
-
30
- # Public: Create or fetch the filter for the given {{src_root}} asset root.
31
- #
32
- # src_root - the asset root URL (e.g. https://cdn.jsdelivr.net/gh/azadeh-afzar/OpenMoji-Jekyll-Plugin@latest)
33
- # asset_path - the asset sub-path of src (e.g. "/images/color/svg")
34
- #
35
- # if asset_path it's not provided by user in _config.yml file, html pipeline module
36
- # will default it to value "emoji"
37
- #
38
- # examples of _config.yml:
39
- # 1. user provided all URLs:
40
- # emoji:
41
- # src: https://example.com/asset
42
- # asset: /images/png
43
- # emoji files will serve from https://example.com/asset/images/png
44
- #
45
- # 2. user provided just src:
46
- # emoji:
47
- # src: https://example.com/asset
48
- # emoji files will serve from https://example.com/emoji
49
- #
50
- # 3. user provided nothing:
51
- # emoji files will serve from https://cdn.jsdelivr.net/gh/azadeh-afzar/OpenMoji-Jekyll-Plugin@latest/images/color/svg
52
- #
53
- # Returns an HTML::Pipeline instance for the given asset root.
54
- def filter_with_emoji(src_root, asset_path)
55
- filters[src_root] ||= HTML::Pipeline.new([
56
- HTML::Pipeline::EmojiFilter,
57
- ], :asset_root => src_root, :asset_path => asset_path, :img_attrs => { :align => nil })
58
- end
59
-
60
- # Public: Filters hash where the key is the asset root source.
61
- # Effectively a cache.
62
- def filters
63
- @filters ||= {}
64
- end
65
-
66
- # Public: Calculate the asset root source for the given config.
67
- # The custom emoji asset root can be defined in the config as
68
- # emoji.src, and must be a valid URL (i.e. it must include a
69
- # protocol and valid domain)
70
- #
71
- # config - the hash-like configuration of the document's site
72
- #
73
- # Returns a full URL to use as the asset root URL. Defaults to the root
74
- # URL for assets provided by an ASSET_HOST_URL environment variable,
75
- # otherwise the root URL for emoji assets at https://cdn.jsdelivr.net/gh/azadeh-afzar/OpenMoji-Jekyll-Plugin@latest.
76
- def emoji_src_root(config = {})
77
- if config.key?("emoji") && config["emoji"].key?("src")
78
- config["emoji"]["src"]
79
- else
80
- default_asset_root
81
- end
82
- end
83
-
84
- # Public: Calculate the asset root source for the given config.
85
- # The custom emoji asset root can be defined in the config as
86
- # emoji.asset.
87
- #
88
- # If emoji.asset isn't defined, its value will explicitly set to "emoji"
89
- #
90
- # config - the hash-like configuration of the document's site
91
- #
92
- # Returns a string to use as the asset path. Defaults to the ASSET_PATH.
93
- def emoji_asset_path(config = {})
94
- if config.key?("emoji") && config["emoji"].key?("src")
95
- if config["emoji"].key?("asset")
96
- config["emoji"]["asset"].chomp("/") + FILE_NAME.to_s
97
- else
98
- "#{DEFAULT_DIR}#{FILE_NAME}"
99
- end
100
- else
101
- "#{ASSET_PATH}#{FILE_NAME}"
102
- end
103
- end
104
-
105
- # Public: Defines the conditions for a document to be emojiable.
106
- #
107
- # doc - the Jekyll::Document or Jekyll::Page
108
- #
109
- # Returns true if the doc is written & is HTML.
110
- def emojiable?(doc)
111
- (doc.is_a?(Jekyll::Page) || doc.write?) &&
112
- doc.output_ext == ".html" || (doc.permalink&.end_with?("/"))
113
- end
114
-
115
- private
116
-
117
- def default_asset_root
118
- if !ENV["ASSET_HOST_URL"].to_s.empty?
119
- # Ensure that any trailing "/" is trimmed
120
- asset_host_url = ENV["ASSET_HOST_URL"].chomp("/")
121
- asset_host_url.to_s
122
- else
123
- OPENMOJI_ASSET_HOST_URL.to_s
124
- end
125
- end
126
-
127
- def replace_document_body(doc)
128
- src_root = emoji_src_root(doc.site.config)
129
- asset_path = emoji_asset_path(doc.site.config)
130
- head, opener, tail = doc.output.partition(OPENING_BODY_TAG_REGEX)
131
- body_content, *rest = tail.partition("</body>")
132
- processed_markup = filter_with_emoji(src_root, asset_path).call(body_content)[:output].to_s
133
- String.new(head) << opener << processed_markup << rest.join
134
- end
135
- end
136
- end
137
- end
138
-
139
- Jekyll::Hooks.register [:pages, :documents], :post_render do |doc|
140
- Jekyll::Emoji.emojify(doc) if Jekyll::Emoji.emojiable?(doc)
141
- end
3
+ require "jekyll-openmoji/plugin"
@@ -0,0 +1,165 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+ require "negarmoji"
5
+ require "html/pipeline"
6
+ require "html/pipeline/negarmoji-pipeline"
7
+
8
+ module Jekyll
9
+ class Emoji
10
+ OPENMOJI_ASSET_HOST_URL = "https://cdn.jsdelivr.net/gh/azadeh-afzar/OpenMoji-Jekyll-Plugin@latest"
11
+ ASSET_PATH = "/images/color/svg"
12
+ DEFAULT_DIR = "/emoji"
13
+ FILE_NAME = "/:file_name"
14
+ DEFAULT_EXTENSION = "svg"
15
+ BODY_START_TAG = "<body"
16
+ OPENING_BODY_TAG_REGEX = %r!<body(.*?)>\s*!m.freeze
17
+
18
+ class << self
19
+ def emojify(doc)
20
+ return unless doc.output =~ HTML::Pipeline::NegarMojiHtmlPipeline::NegarehEmojiFilter
21
+ .emoji_pattern
22
+
23
+ doc.output = if doc.output.include? BODY_START_TAG
24
+ replace_document_body(doc)
25
+ else
26
+ src_root = emoji_src_root(doc.site.config)
27
+ asset_path = emoji_asset_path(doc.site.config)
28
+ file_extension = emoji_extension(doc.site.config)
29
+ filter_with_emoji(src_root, asset_path, file_extension)
30
+ .call(doc.output)[:output].to_s
31
+ end
32
+ end
33
+
34
+ # Public: Create or fetch the filter for the given {{src_root}} asset root.
35
+ #
36
+ # src_root - the asset root URL (e.g. https://cdn.jsdelivr.net/gh/azadeh-afzar/OpenMoji-Jekyll-Plugin@latest)
37
+ # asset_path - the asset sub-path of src (e.g. "/images/color/svg") [default = "emoji"]
38
+ # extension - the extension of emoji image files, [default = svg ]
39
+ #
40
+ # examples of _config.yml:
41
+ # 1. user provided all URLs:
42
+ # emoji:
43
+ # src: https://example.com/asset
44
+ # asset: /images/png
45
+ # emoji files will serve from https://example.com/asset/images/png
46
+ #
47
+ # 2. user provided just src:
48
+ # emoji:
49
+ # src: https://example.com/asset
50
+ # emoji files will serve from https://example.com/emoji
51
+ #
52
+ # 3. user provided nothing:
53
+ # emoji files will serve from https://cdn.jsdelivr.net/gh/azadeh-afzar/OpenMoji-Jekyll-Plugin@latest/images/color/svg
54
+ #
55
+ # Returns an HTML::Pipeline instance for the given asset root.
56
+ def filter_with_emoji(src_root, asset_path, file_extension)
57
+ filters[src_root] ||= HTML::Pipeline.new([HTML::Pipeline::
58
+ NegarMojiHtmlPipeline::NegarehEmojiFilter],
59
+ :asset_root => src_root,
60
+ :asset_path => asset_path,
61
+ :extension => file_extension,
62
+ :img_attrs => {:align => nil})
63
+ end
64
+
65
+ # Public: Filters hash where the key is the asset root source.
66
+ # Effectively a cache.
67
+ def filters
68
+ @filters ||= {}
69
+ end
70
+
71
+ # Public: Calculate the asset root source for the given config.
72
+ # The custom emoji asset root can be defined in the config as
73
+ # emoji.src, and must be a valid URL (i.e. it must include a
74
+ # protocol and valid domain)
75
+ #
76
+ # config - the hash-like configuration of the document's site
77
+ #
78
+ # Returns a full URL to use as the asset root URL. Defaults to the root
79
+ # URL for assets provided by an ASSET_HOST_URL environment variable,
80
+ # otherwise the root URL for emoji assets at https://cdn.jsdelivr.net/gh/azadeh-afzar/OpenMoji-Jekyll-Plugin@latest.
81
+ def emoji_src_root(config = {})
82
+ if config.key?("emoji") && config["emoji"].key?("src")
83
+ config["emoji"]["src"]
84
+ else
85
+ default_asset_root
86
+ end
87
+ end
88
+
89
+ # Public: Calculate the asset root source for the given config.
90
+ # The custom emoji asset root can be defined in the config as
91
+ # emoji.asset.
92
+ #
93
+ # If emoji.asset isn't defined, its value will explicitly set to "emoji"
94
+ #
95
+ # config - the hash-like configuration of the document's site
96
+ #
97
+ # Returns a string to use as the asset path. Defaults to the ASSET_PATH.
98
+ def emoji_asset_path(config = {})
99
+ if config.key?("emoji") && config["emoji"].key?("src")
100
+ if config["emoji"].key?("asset")
101
+ config["emoji"]["asset"].chomp("/") + FILE_NAME.to_s
102
+ else
103
+ "#{DEFAULT_DIR}#{FILE_NAME}"
104
+ end
105
+ else
106
+ "#{ASSET_PATH}#{FILE_NAME}"
107
+ end
108
+ end
109
+
110
+ # Public: return extension for emoji files.
111
+ # The custom emoji extension can be defined in the config as
112
+ # emoji.extension.
113
+ #
114
+ # If emoji.extension isn't defined, its value will explicitly set to "svg"
115
+ #
116
+ # config - the hash-like configuration of the document's site
117
+ #
118
+ # Returns a string to use as the extension. Defaults to the DEFAULT_EXTENSION.
119
+ def emoji_extension(config = {})
120
+ if config.key?("emoji") && config["emoji"].key?("extension")
121
+ config["emoji"]["extension"]
122
+ else
123
+ DEFAULT_EXTENSION.to_s
124
+ end
125
+ end
126
+
127
+ # Public: Defines the conditions for a document to be emojiable.
128
+ #
129
+ # doc - the Jekyll::Document or Jekyll::Page
130
+ #
131
+ # Returns true if the doc is written & is HTML.
132
+ def emojiable?(doc)
133
+ (doc.is_a?(Jekyll::Page) || doc.write?) &&
134
+ doc.output_ext == ".html" || (doc.permalink&.end_with?("/"))
135
+ end
136
+
137
+ private
138
+
139
+ def default_asset_root
140
+ if !ENV["ASSET_HOST_URL"].to_s.empty?
141
+ # Ensure that any trailing "/" is trimmed
142
+ asset_host_url = ENV["ASSET_HOST_URL"].chomp("/")
143
+ asset_host_url.to_s
144
+ else
145
+ OPENMOJI_ASSET_HOST_URL.to_s
146
+ end
147
+ end
148
+
149
+ def replace_document_body(doc)
150
+ src_root = emoji_src_root(doc.site.config)
151
+ asset_path = emoji_asset_path(doc.site.config)
152
+ file_extension = emoji_extension(doc.site.config)
153
+ head, opener, tail = doc.output.partition(OPENING_BODY_TAG_REGEX)
154
+ body_content, *rest = tail.partition("</body>")
155
+ processed_markup = filter_with_emoji(src_root, asset_path, file_extension)
156
+ .call(body_content)[:output].to_s
157
+ String.new(head) << opener << processed_markup << rest.join
158
+ end
159
+ end
160
+ end
161
+ end
162
+
163
+ Jekyll::Hooks.register [:pages, :documents], :post_render do |doc|
164
+ Jekyll::Emoji.emojify(doc) if Jekyll::Emoji.emojiable?(doc)
165
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ class Emoji
5
+ VERSION = "0.0.3"
6
+ end
7
+ end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-openmoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mohammad Mahdi Baghbani Pourvahid
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-13 00:00:00.000000000 Z
11
+ date: 2019-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: gemoji
14
+ name: html-pipeline
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '2.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: html-pipeline
28
+ name: html-pipeline-negarmoji
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.2'
33
+ version: 0.0.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.2'
40
+ version: 0.0.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: jekyll
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -64,14 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: 0.1.0
67
+ version: 0.1.1
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 0.1.0
74
+ version: 0.1.1
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: bundler
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -128,15 +128,47 @@ dependencies:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0.4'
131
- description:
131
+ - !ruby/object:Gem::Dependency
132
+ name: simplecov
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: 0.17.0
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: 0.17.0
145
+ description: |-
146
+ %q{OpenMoji emoji pack plugin for Jekyll with a powerful configuration options
147
+ and support for various emoji image file sources and extensions}
132
148
  email: MahdiBaghbani@protonmail.com
133
149
  executables: []
134
150
  extensions: []
135
151
  extra_rdoc_files: []
136
152
  files:
153
+ - ".gitignore"
154
+ - ".gitlab-ci.yml"
155
+ - ".rspec"
156
+ - ".rubocop.yml"
157
+ - ".rubocop_todo.yml"
158
+ - ".travis.yml"
159
+ - CHANGELOG.md
160
+ - CODE_OF_CONDUCT.md
161
+ - CONTRIBUTING.md
162
+ - Gemfile
137
163
  - LICENSE
138
164
  - README.md
165
+ - ROADMAP.md
166
+ - Rakefile
167
+ - SUPPORT.md
168
+ - jekyll-openmoji.gemspec
139
169
  - lib/jekyll-openmoji.rb
170
+ - lib/jekyll-openmoji/plugin.rb
171
+ - lib/jekyll-openmoji/version.rb
140
172
  homepage: https://gitlab.com/Azadeh-Afzar/Web-Development/OpenMoji-Jekyll-Plugin
141
173
  licenses:
142
174
  - GPL-3.0