jekyll_google_translate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 63793738bc79e3d5d47d68f4e2b45f332cbac0e154b2afaea864569d69033f6e
4
+ data.tar.gz: ca20591a93926b7463bd2c32685eee770508a0d5fcf333ad9f40f50e18f6a8fd
5
+ SHA512:
6
+ metadata.gz: 4dcff495fca527f84ea5cf21fc13cf03d8a412edc5720a408249d966116cfb0ed758d796009b3aa07e1aef8571c8c5f7971eeb4381387f1e5f1f2246a8b85156
7
+ data.tar.gz: 6a9695a887cf5627f41cdf30385b80107c13afb83e76e77f2a8dfa8b690f85a485b00d19ec51aac455c2db09df64c782189c18d0d9bcafae939fb6455eed8a9e
data/.rubocop.yml ADDED
@@ -0,0 +1,71 @@
1
+ require:
2
+ # - rubocop-jekyll
3
+ - rubocop-md
4
+ - rubocop-performance
5
+ - rubocop-rake
6
+ - rubocop-rspec
7
+
8
+ AllCops:
9
+ Exclude:
10
+ - binstub/**/*
11
+ - exe/**/*
12
+ - vendor/**/*
13
+ - Gemfile*
14
+ NewCops: enable
15
+ TargetRubyVersion: 3.1.3
16
+
17
+ Gemspec/DeprecatedAttributeAssignment:
18
+ Enabled: false
19
+
20
+ Gemspec/RequireMFA:
21
+ Enabled: false
22
+
23
+ Layout/HashAlignment:
24
+ EnforcedColonStyle: table
25
+ EnforcedHashRocketStyle: table
26
+
27
+ Layout/LineLength:
28
+ Max: 150
29
+
30
+ Metrics/AbcSize:
31
+ Max: 35
32
+
33
+ Metrics/BlockLength:
34
+ Exclude:
35
+ - jekyll_google_translate.gemspec
36
+ Max: 30
37
+
38
+ Metrics/CyclomaticComplexity:
39
+ Max: 15
40
+
41
+ Metrics/MethodLength:
42
+ Max: 40
43
+
44
+ Metrics/ModuleLength:
45
+ Enabled: false
46
+
47
+ Metrics/PerceivedComplexity:
48
+ Max: 15
49
+
50
+ Naming/FileName:
51
+ Exclude:
52
+ - Rakefile
53
+
54
+ Style/Documentation:
55
+ Enabled: false
56
+
57
+ Style/FrozenStringLiteralComment:
58
+ Enabled: false
59
+
60
+ Style/TrailingCommaInHashLiteral:
61
+ EnforcedStyleForMultiline: comma
62
+
63
+ RSpec/FilePath:
64
+ IgnoreMethods: true
65
+ SpecSuffixOnly: true
66
+
67
+ RSpec/ExampleLength:
68
+ Max: 30
69
+
70
+ RSpec/MultipleExpectations:
71
+ Max: 15
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Change Log
2
+
3
+ ## 0.1.0
4
+
5
+ * Initial release.
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # `Jekyll_google_translate` [![Gem Version](https://badge.fury.io/rb/jekyll_google_translate.svg)](https://badge.fury.io/rb/jekyll_google_translate)
2
+
3
+ Adds Google Translate to a web page.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add the following to your Jekyll website's `Gemfile`:
9
+
10
+ ```ruby
11
+ group :jekyll_plugins do
12
+ gem 'jekyll_google_translate'
13
+ end
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```shell
19
+ $ bundle
20
+ ```
21
+
22
+ Copy `demo/assets/css/jekyll_google_translate.css` to your Jekyll web site's CSS directory,
23
+ and update your layout accordingly.
24
+
25
+
26
+ ## Usage
27
+
28
+ The {% google_translate_html %} tag must be called to insert HTML into the page,
29
+ then the {% google_translate_javascript %} tag must be called to insert Javascript into the page.
30
+ For example:
31
+
32
+ ```html
33
+ <!DOCTYPE html>
34
+ <html lang="{{ site.lang | default: "en-US" }}">
35
+ <head>
36
+ <link rel="stylesheet" href="{{ '/assets/css/style.css?v=' | append: nowMillis }}" type="text/css">
37
+ <link rel="stylesheet" href="{{ '/assets/css/jekyll_google_translate.css?v=' | append: nowMillis }}" type="text/css">
38
+ </head>
39
+ <body>
40
+ <nav id="sidebar">
41
+ {% google_translate_html %}
42
+ </nav>
43
+ </body>
44
+ {% google_translate_javascript %}
45
+ </html>
46
+ ```
47
+
48
+ The above is usually incorporated into a layout, for example, `_layouts/default.html`.
49
+
50
+
51
+ ## Development
52
+
53
+ After checking out this git repository, install dependencies by typing:
54
+
55
+ ```shell
56
+ $ bin/setup
57
+ ```
58
+
59
+ You should do the above before running Visual Studio Code.
60
+
61
+
62
+ ### Run the Tests
63
+
64
+ ```shell
65
+ $ bundle exec rake test
66
+ ```
67
+
68
+
69
+ ### Interactive Session
70
+
71
+ The following will allow you to experiment:
72
+
73
+ ```shell
74
+ $ bin/console
75
+ ```
76
+
77
+
78
+ ### Local Installation
79
+
80
+ To install this gem onto your local machine, type:
81
+
82
+ ```shell
83
+ $ bundle exec rake install
84
+ ```
85
+
86
+
87
+ ### To Release A New Version
88
+
89
+ To create a git tag for the new version, push git commits and tags,
90
+ and push the new version of the gem to https://rubygems.org, type:
91
+
92
+ ```shell
93
+ $ bundle exec rake release
94
+ ```
95
+
96
+
97
+ ## Contributing
98
+
99
+ Bug reports and pull requests are welcome at https://github.com/mslinn/jekyll_google_translate.
100
+
101
+
102
+ ## License
103
+
104
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ desc 'Bump patch version'
11
+ task :patch do
12
+ system 'gem bump --tag'
13
+ end
14
+
15
+ desc 'Bump minor version'
16
+ task :minor do
17
+ system 'gem bump --version minor --tag'
18
+ end
19
+
20
+ desc 'Bump major version'
21
+ task :major do
22
+ system 'gem bump --version major --tag'
23
+ end
24
+
25
+ task publish: [:build] do
26
+ $VERBOSE = nil
27
+ load 'jekyll_google_translate/version.rb'
28
+ system "gem push pkg/jekyll_google_translate-#{JekyllGoogleTranslate::VERSION}.gem"
29
+ end
30
+
31
+ desc 'Bump patch version, create git tag, build the gem and release to geminabox (default)'
32
+ task release_patch: %i[test patch publish]
33
+
34
+ desc 'Bump minor version, create git tag, build the gem and release to geminabox'
35
+ task release_minor: %i[test minor publish]
36
+
37
+ desc 'Bump major version, create git tag, build the gem and release to geminabox'
38
+ task release_major: %i[test major publish]
39
+
40
+ task default: :test
@@ -0,0 +1,34 @@
1
+ require_relative 'lib/jekyll_google_translate/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ host = 'https://github.com/mslinn/jekyll_google_translate'
5
+
6
+ spec.authors = ['Mike Slinn']
7
+ spec.description = <<~END_DESC
8
+ Write a longer description of the gem.
9
+ Use as many lines as you like.
10
+ END_DESC
11
+ spec.email = ['mslinn@mslinn.com']
12
+ spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
13
+ spec.homepage = 'https://github.com/mslinn/jekyll_google_translate'
14
+ spec.license = 'MIT'
15
+ spec.metadata = {
16
+ 'allowed_push_host' => 'https://rubygems.org',
17
+ 'bug_tracker_uri' => "#{host}/issues",
18
+ 'changelog_uri' => "#{host}/CHANGELOG.md",
19
+ 'homepage_uri' => spec.homepage,
20
+ 'source_code_uri' => host,
21
+ }
22
+ spec.name = 'jekyll_google_translate'
23
+ spec.post_install_message = <<~END_MESSAGE
24
+
25
+ Thanks for installing #{spec.name}!
26
+
27
+ END_MESSAGE
28
+ spec.require_paths = ['lib']
29
+ spec.required_ruby_version = '>= 3.1.0'
30
+ spec.summary = 'Write summary of what the gem is for'
31
+ spec.version = JekyllGoogleTranslate::VERSION
32
+ spec.add_dependency 'jekyll', '>= 3.5.0'
33
+ spec.add_dependency 'jekyll_plugin_support', '>= 0.7.0'
34
+ end
@@ -0,0 +1,32 @@
1
+ require 'jekyll_plugin_support'
2
+ require_relative 'jekyll_google_translate/version'
3
+
4
+ # This Jekyll tag plugin inserts HTML for Google Translate.
5
+ # The {% google_translate_javascript %} tag must also be called to insert JavaScript into the page.
6
+ #
7
+ # The Jekyll log level defaults to :info, which means all the Jekyll.logger statements below will not generate output.
8
+ # You can control the log level when you start Jekyll.
9
+ # To set the log level to :debug, write an entry into _config.yml, like this:
10
+ # plugin_loggers:
11
+ # GoogleTranslateHtml: debug
12
+ module JekyllGoogleTranslate
13
+ class GoogleTranslateHtml < JekyllSupport::JekyllTag
14
+ PLUGIN_NAME = 'google_translate_html'.freeze
15
+ VERSION = JekyllGoogleTranslate::VERSION
16
+
17
+ # The following variables are predefined:
18
+ # @argument_string, @config, @envs, @helper, @layout, @logger, @mode, @page, @paginator, @site, @tag_name and @theme
19
+ #
20
+ # @param tag_name [String] is the name of the tag, which we already know.
21
+ # @param argument_string [String] the arguments from the web page.
22
+ # @param tokens [Liquid::ParseContext] tokenized command line
23
+ # @return [void]
24
+ def render_impl
25
+ <<~END_OUTPUT
26
+ <div id="google_translate_element"></div>
27
+ END_OUTPUT
28
+ end
29
+
30
+ JekyllPluginHelper.register(self, PLUGIN_NAME)
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ require 'jekyll_plugin_support'
2
+ require_relative 'jekyll_google_translate/version'
3
+
4
+ # This Jekyll tag plugin inserts JavaScript for Google Translate.
5
+ # The {% google_translate_html %} tag must also be called to insert HTML into the page.
6
+ #
7
+ # The Jekyll log level defaults to :info, which means all the Jekyll.logger statements below will not generate output.
8
+ # You can control the log level when you start Jekyll.
9
+ # To set the log level to :debug, write an entry into _config.yml, like this:
10
+ # plugin_loggers:
11
+ # GoogleTranslateJavascript: debug
12
+ module JekyllGoogleTranslate
13
+ class GoogleTranslateJavascript < JekyllSupport::JekyllTag
14
+ PLUGIN_NAME = 'google_translate_javascript'.freeze
15
+ VERSION = JekyllGoogleTranslate::VERSION
16
+
17
+ # The following variables are predefined:
18
+ # @argument_string, @config, @envs, @helper, @layout, @logger, @mode, @page, @paginator, @site, @tag_name and @theme
19
+ #
20
+ # @param tag_name [String] is the name of the tag, which we already know.
21
+ # @param argument_string [String] the arguments from the web page.
22
+ # @param tokens [Liquid::ParseContext] tokenized command line
23
+ # @return [void]
24
+ def render_impl
25
+ <<~END_OUTPUT
26
+ <script type="text/javascript">
27
+ function googleTranslateElementInit() {
28
+ new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
29
+ }
30
+ </script>
31
+ <script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
32
+ END_OUTPUT
33
+ end
34
+
35
+ JekyllPluginHelper.register(self, PLUGIN_NAME)
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module JekyllGoogleTranslate
2
+ VERSION = '0.1.0'.freeze unless defined? VERSION
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'jekyll'
2
+ require 'jekyll_plugin_logger'
3
+ require 'jekyll_plugin_support'
4
+
5
+ require_relative 'jekyll_google_translate/version'
6
+
7
+ # Require all Ruby files in 'lib/', except this file
8
+ Dir[File.join(__dir__, '*.rb')].each do |file|
9
+ require file unless file.end_with?('/jekyll_google_translate.rb')
10
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../lib/jekyll_google_translate'
2
+
3
+ RSpec.describe JekyllGoogleTranslate::JekyllGoogleTranslate do
4
+ let(:logger) do
5
+ PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
6
+ end
7
+
8
+ let(:parse_context) { TestParseContext.new }
9
+
10
+ it 'has a test' do
11
+ expect(true).to be_true
12
+ end
13
+ end
@@ -0,0 +1,79 @@
1
+ require 'jekyll'
2
+ require 'jekyll_plugin_logger'
3
+ require 'liquid'
4
+ require 'fileutils'
5
+ require 'yaml'
6
+ require_relative '../lib/<%= @gem_name %>'
7
+
8
+ RSpec.configure do |config|
9
+ config.filter_run :focus
10
+ # config.order = 'random'
11
+ config.run_all_when_everything_filtered = true
12
+
13
+ # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
14
+ config.example_status_persistence_file_path = '../spec/status_persistence.txt'
15
+
16
+ config.filter_run_when_matching focus: true
17
+ end
18
+
19
+ Registers = Struct.new(:page, :site)
20
+
21
+ # Mock for Collections
22
+ class Collections
23
+ def values
24
+ []
25
+ end
26
+ end
27
+
28
+ # Mock for Site
29
+ class SiteMock
30
+ attr_reader :config
31
+
32
+ def initialize
33
+ @config = YAML.safe_load_file(File.read('../demo/_config.yml'))
34
+ @config['env'] = { 'JEKYLL_ENV' => 'development' }
35
+ end
36
+
37
+ def collections
38
+ Collections.new
39
+ end
40
+ end
41
+
42
+ class TestLiquidContext < Liquid::Context
43
+ def initialize
44
+ super
45
+
46
+ page = {
47
+ 'content' => 'blah blah',
48
+ 'description' => 'Jekyll plugin support demo',
49
+ 'dir' => '/',
50
+ 'excerpt' => nil,
51
+ 'layout' => 'default',
52
+ 'name' => 'index.html',
53
+ 'path' => 'index.html',
54
+ 'title' => 'Welcome',
55
+ 'url' => '/',
56
+ }
57
+
58
+ @content = 'Interior of the tag'
59
+ @registers = Registers.new(
60
+ page,
61
+ SiteMock.new
62
+ )
63
+ end
64
+ end
65
+
66
+ # Mock for Liquid::ParseContent
67
+ class TestParseContext < Liquid::ParseContext
68
+ attr_reader :line_number, :registers
69
+
70
+ def initialize
71
+ super
72
+ @line_number = 123
73
+
74
+ @registers = Registers.new(
75
+ { 'path' => 'path/to/page.html' },
76
+ SiteMock.new
77
+ )
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_google_translate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Slinn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: jekyll_plugin_support
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.0
41
+ description: |
42
+ Write a longer description of the gem.
43
+ Use as many lines as you like.
44
+ email:
45
+ - mslinn@mslinn.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".rubocop.yml"
51
+ - CHANGELOG.md
52
+ - README.md
53
+ - Rakefile
54
+ - jekyll_google_translate.gemspec
55
+ - lib/google_translate_html.rb
56
+ - lib/google_translate_javascript.rb
57
+ - lib/jekyll_google_translate.rb
58
+ - lib/jekyll_google_translate/version.rb
59
+ - spec/jekyll_google_translate_spec.rb
60
+ - spec/spec_helper.rb
61
+ homepage: https://github.com/mslinn/jekyll_google_translate
62
+ licenses:
63
+ - MIT
64
+ metadata:
65
+ allowed_push_host: https://rubygems.org
66
+ bug_tracker_uri: https://github.com/mslinn/jekyll_google_translate/issues
67
+ changelog_uri: https://github.com/mslinn/jekyll_google_translate/CHANGELOG.md
68
+ homepage_uri: https://github.com/mslinn/jekyll_google_translate
69
+ source_code_uri: https://github.com/mslinn/jekyll_google_translate
70
+ post_install_message: |2+
71
+
72
+ Thanks for installing jekyll_google_translate!
73
+
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 3.1.0
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 3.3.7
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Write summary of what the gem is for
92
+ test_files: []
93
+ ...