Loading local libaries in jekyll (Liquid template library + ruby bundler) - ruby

My question is: How do I load local libaries in ruby and with bundler + jekyll?
I'm trying to load a bunch of local libraries.
For example: project_root/_plugins/fileexists.rb
I've tried following https://jekyllrb.com/docs/plugins/ but that solution assumes you have a library that can be installed from the global Gem repository.
The plugins I'm trying to load are here https://github.com/nicnocquee/appolo/tree/master/_plugins
The error I'm getting when doing 'bundle exec jekyll serve':
Dependency Error: Yikes! It looks like you don't have fileexists or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. The full error message from Ruby is: 'cannot load such file -- fileexists' If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/!
To complicate the matter, I'm using the Liquid template library. (Though this shouldnt be a Liquid problem because I get the error when doing bundle exec jekyll serve. I think..)
{% file_exists {{ fb_img_default }} %}
The code for the template is here:
https://github.com/nicnocquee/appolo/blob/master/_includes/head.html#L25
My _config.yml file for jekyll: https://pastebin.com/SphuLcVt
The Gemfile: https://pastebin.com/3ptcBx5m
Thanks in advance for ideas about how to proceed!
Library version
bundle --version
Bundler version 1.16.0
ruby --version
ruby 2.3.3p222 (2016-11-21) [x86_64-linux-gnu]
gem --version
2.5.2

Ok, I figured this out.
I removed:
plugins:
- fileexists
From _config.yml
And removed:
gem 'fileexists', :path => '/home/test/xxx.github.io/_plugins/fileexists'
gem 'github-pages'
from Gemfile
The clue that github-pages packet was the problem: https://github.com/jekyll/jekyll/issues/5990#issuecomment-308231021
Short answer:
"No custom plugins will load when using github-pages because of their whitelist."

Related

Is the net/http gem not in the default library for Ruby?

I want to create a Gemfile.lock by typing 'bundle install' but my local machine can't find the gem net/http. I've tried typing 'bundle update net/http' & 'bundle --full-index' & 'gem install bundler' but I keep getting this error when I try 'bundle install' again:
Could not find gem 'net/http' in rubygems repository https://rubygems.org/ or installed locally. The source does not contain any versions of 'net/http'
my Gemfile resembles the following:
source "https://rubygems.org"
gem 'open-uri'
gem 'nokogiri'
gem 'net/http'
gem 'pry'
Other solutions to this problem suggest removing the line for gem net/http because net/http is part of the default library for Ruby...however when I do this everything loads fine, and I can create a Gemfile.lock upon typing 'bundle install' but when I run my code I get the following error:
Traceback (most recent call last):
run.rb:4:in `': uninitialized constant Net (NameError)
Did you mean? Set
The line of code this refers to is
response = Net::HTTP.get(url)
I'm running Ruby version 2.6.1
The name of the gem is net-http. It is one of the first hits when you google for "net/http".
However, in Ruby 2.6.1, net/http is still part of the standard library, not a gem. Net/http was only removed from the standard library in Ruby 3.0.
There are two different kinds of standard gems:
Default gems: These gems are part of Ruby and you can always require them directly. You cannot remove them. They are maintained by Ruby core.
Bundled gems: The behavior of bundled gems is similar to normal gems, but they get automatically installed when you install Ruby. They can be uninstalled and they are maintained outside of Ruby core.
Your problem is the wrong name gem ('net-http' instead of 'net/http', you can run gem search ^net to find out remote gems start by 'net').
If the gem is 'default', no need to declare it in Gemfile.
You can check standard default gems on: https://stdgems.org/

Ruby - Cannot use locally installed gem

I've written a simple PasswordGenerator gem that I have at ~/workspace/gems/password_generator and have an app at ~/workspace/rubysamples/app where I want to use it. I have a Gemfile, the content of it is this:
gem 'password_generator', path: '~/workspace/gems/password_generator'
I installed it locally, like this:
bundle install --local
Resolving dependencies...
Using bundler 1.16.5
Using password_generator 0.1.0 from source at `~/workspace/gems/password_generator`
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
It looks like it's installed locally:
bundle info password_generator
* password_generator (0.1.0)
Summary: Simple password generator
Homepage: https://github.com/jedrekdomanski/password_generator
Path: /home/jedrek/workspace/gems/password_generator
When I try to use it
~/workspace/rubysamples/app/password_reset.rb
PasswordGenerator.generate
I get an error
uninitialized constant PasswordGenerator (NameError)
What am I doing wrong? Am I missing anything?
Here's my gem repo: https://github.com/jedrekdomanski/password_generator
I also tried pointing to my repo and branch in the Gemfile
gem 'password_generator', git: 'git#github.com:jedrekdomanski/password_generator.git', branch: 'master'
but I get the same error message uninitialized constant PasswordGenerator (NameError)
There are potentially two issues. The first is how you are starting Ruby and the second is how you are requiring your module.
First, if you are starting Ruby by running ruby password_reset.rb then you are ignoring the Gemfile. The Gemfile is only used when you're using bundler, so you want to make sure you are starting Ruby by running bundle exec ruby password_reset.rb. This causes bundler to read your Gemfile and execute Ruby in that context.
Second, you're not properly including your module in your Ruby file. Just because you've added the gem to your Gemfile and started Ruby using bundler doesn't mean that the Ruby process knows you intend to use that gem's module; it just makes the module available for use. You might wonder, "Why don't I have to do that in Rails?" Because Rails does that for you automatically via config/application.rb.
Given these two issues, the correct way to accomplish your goal is to configure your app as follows:
First, create your Gemfile:
# Gemfile
gem 'password_generator', path: '~/workspace/gems/password_generator'
Second, create your password_reset.rb file:
# password_reset.rb
# Manually require any libraries that this app will use, even if defined in Gemfile
require 'password_generator'
# Call `puts` so something is printed to the console when this app runs
puts PasswordGenerator.generate
Third, run bundle install to ensure your Gemfile is properly formatted and to generate your Gemfile.lock:
⇒ bundle install
Using bundler 1.16.5
Using password_generator 0.1.0 from source at `../../gems/password_generator`
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Fourth, run bundle exec ruby password_reset.rb and observe the output:
⇒ bundle exec ruby password_reset.rb
kpiDfyTxtdAsKmYuZqmK
Everything works because:
Ruby is started with Bundler
Bundler reads your Gemfile and makes the gems available to Ruby
Your app requires the module from the gem before attempting to use the module

jekyll-multiple-languages-plugin cannot be found

I'm newbie to Ruby and Jekyll. Recently I've tried to install Jekyll Multiple Languages Plugin onto my GitLab Pages instance. I've managed to successfully add
'gem install jekyll-multiple-languages-plugin
bundle install'
into the .gitlab-ci.yml but when I try to add
gems:
jekyll-multiple-languages-plugin
into _config.yml in order to use it on the site my commit fails with the following error:
Using jekyll-watch 1.5.0
Using jekyll 3.4.3
Bundle complete! 3 Gemfile dependencies, 20 gems now installed.
Bundled gems are installed into /usr/local/bundle.
$ jekyll build -d public
Configuration file: /builds/myusername/forty-jekyll-theme/_config.yml
Dependency Error: Yikes! It looks like you don't have jekyll-multiple-languages-plugin or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. The full error message from Ruby is: 'cannot load such file -- jekyll-multiple-languages-plugin' If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/!
jekyll 3.4.3 | Error: jekyll-multiple-languages-plugin
ERROR: Job failed: exit code 1
I have used this method because any attempt to edit Gemfile ends up in commit error. I've also tried to do all presented steps except adding bundle install. In that case I get the same error, but the beginning looks like:
18 gems installed
$ gem install jekyll-multiple-languages-plugin
Successfully installed jekyll-multiple-languages-plugin-1.5.1
1 gem installed
$ jekyll build -d public
I did not manage to find the way to solve it on Stack Overflow nor other sites. For example this did not help
With the awesome support of allejo from Jekyll's IRC channel I've managed to solve the problem. Here are the steps:
I've used Gemfile. Now it looks like
source 'https://rubygems.org'
gem 'jekyll'
group :jekyll_plugins do
gem 'jekyll-multiple-languages-plugin'
end
The second modified thing was .gitlab-ci.yml (the first line - image: ruby - is also included)
image: ruby
pages:
stage: build
script:
# - gem install jekyll
- gem install bundler
# - gem install jekyll-multiple-languages-plugin
- bundle install
- bundle exec jekyll build -d public
# - jekyll build -d public
artifacts:
paths:
- public
only:
- master
It produced a bug, but it was only caused by the lack of declared language which is part of standard plugin configuration.

Jekyll - getting an error when I have Paginate in my project

I'm running 3.1.2 on Windows
When I try to add 'Paginate' to my project, I'm getting an error in cmd
Deprecation: You appear to have pagination turned on, but you haven't
included the jekyll-paginate gem. Ensure you have gems:
[jekyll-paginate] in your configuration file.
I have jekyll-paginate (1.1.0) and paginate (4.0.0) installed and it's still giving this error.
Here is my _config.yml file:
paginate: 4
paginate_path: '/blog/page:num/'
And my index.html page
{% for post in paginator.posts limit: 4 %}
What should I check, to resolve this?
Jekyll guys have removed Paginate plugin from version 3.x as it did not play nicely with more core features. You can still enable it using any of these three options
In your site source root, make a _plugins directory. Place your plugins here. Any file ending in *.rb inside this directory will be loaded before Jekyll generates your site.
In your _config.yml file, add a new array with the key gems and the values of the gem names of the plugins you’d like to use. An example:
gems: [jekyll-coffeescript, jekyll-watch, jekyll-assets]
# This will require each of these gems automatically.
Then install your plugins using gem install jekyll-paginate-category jekyll-watch jekyll-assets
Add the relevant plugins to a Bundler group in your Gemfile. An example:
group :jekyll_plugins do
gem "my-jekyll-plugin"
gem "jekyll-paginate-category"
end
Now you need to install all plugins from your Bundler group by running single command bundle install
You can find more information on jekyll plugins page
Maybe the issue is that you have 2 versions of Jekyll, one installed through "apt" and another thru "gem". Try to remove the one installed with "apt" (or whatever command you're using) and update the other version using the bundler "bundle update". I have this error I've corrected by removing Jekyll I installed by "apt" command.
** Notes: I'm using Ubuntu.
Make sure you have the following in your _config.yml file.
gems: [jekyll-paginate]

How to resolve error 'While executing gem ... (TypeError) can't convert nil into String'?

I am using using Windows 8 with cygwin. I am trying to configure Omega4 Drupal theme.
I have ruby version 1.9.3p547 (2014-05-14 revision 45962) [x86_64-cygwin]
I have installed ruby gems version 2.4.1 from https://rubygems.org/ , as shown also when I run the gem -v command:
$ gem -v
2.4.1
I have Drupal installed in folder c:\xampp\htdocs\drupal , and cygwin is accessible by cygdrive.
I navigate to the folder of my subtheme and then run the command like so:
$ drush omega-guard
which: no tput in (/home/prem/.rvm/gems/ruby-1.9.3-p547#omega.furniure/bin:/home/ prem/.rvm/gems/ruby-1.9.3-p547#global/bin:/home/prem/.rvm/rubies/ruby-1.9.3-p547 /bin:/home/prem/.rvm/bin:/usr/local/bin:/usr/bin:/cygdrive/c/Program Files (x86)/Intel/iCLS Client:/cygdrive/c/Program Files/Intel/iCLS Client:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files (x86)/Intel/OpenCL SDK/3.0/bin/x86:/cygdrive/c/Program Files (x86)/Intel/OpenCL SDK/3.0/bin/x64:/cygdrive/c/Program Files/Intel/Intel(R) Management Engine Components/DAL:/cygdrive/c/Program Files/Intel/Intel(R) Management Engine Components/IPT:/cygdrive/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/DAL:/cygdrive/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/IPT:/cygdrive/c/Program Files/Java/jre7/bin:/cygdrive/c/Ruby200-x64/bin:/cygdrive/c/Ruby193/bin: /cygdrive/c/ProgramData/Drush:/cygdrive/c/Program Files (x86)/Drush/GnuWin32/bin:/cygdrive/c/Program Files (x86)/Drush/Php:/cygdrive/c/Program Files (x86)/Drush/cwRsync/bin:/cygdrive/c/xampp/php)
Which theme do you want to run Guard for?
[0] : Cancel
[1] : furniure (Subtheme of Omega) - Please provide a description for your
theme.
[2] : Ohm (Subtheme of Omega) - Omega based demonstration theme. Serves as a
best-practice reference for the Omega documentation. Ohm will be
constantly updated as best practice evolves so shouldn't be used in
production.
[3] : Omega - A powerful HTML5 base theme framework utilizing tools like
Sass, Compass, Grunt, Bower, Ruby Version Manager, Bundler and more.
1
There was a problem with your setup: [error]
Resolving dependencies...
Bundler can't satisfy your Gemfile's dependencies.
Install missing gems with `bundle install`.
However when I run the below command I run into an error I don't understand:
$ bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Using addressable 2.3.6
TypeError: can't convert nil into String
An error occurred while installing sass (3.4.1), and Bundler cannot continue.
Make sure that `gem install sass -v '3.4.1'` succeeds before bundling.
$ gem install sass -v 3.4.1
ERROR: While executing gem ... (TypeError)
can't convert nil into String
So my question is about the above error While executing gem ... (TypeError) can't convert nil into String: how can I resolve this error?

Resources