2022年6月3日

ウェブサイトを更新しようとして、自分がslimを使っていることを思い出した。ついでにgemとbundlerの違いも理解。gemだとグローバルインストールだが、bundlerならプロジェクトごと。つまりPythonの仮想環境みたいな奴だな。

とりあえずinitする。

bundle init

こんなGemfileができる。

# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# gem "rails"

最後を書き換える。

gem "slim"

インストール。

bundle install --path vender/bundle

インストールされたか確認。

$ bundle exec gem list

*** LOCAL GEMS ***

bundler (default: 1.17.2)
slim (4.1.0)
temple (0.8.2)
tilt (2.0.10)

実行はbundle exec slimrbでできる。

$ bundle exec slimrb -v 
Slim 4.1.0

Pythonのようにactivate/deactivateで仮想環境に出入りするのが良いのか、Bundlerのように毎回bundle execを実行するのが良いのかは微妙だな。

あとはGemfileとGemfile.lockはリポジトリに追加したほうが良いらしい。.bundlevender/bundle.gitignoreに追加。

makefileで

%.html: %.slim
    slimrb $< -p -r slim/include > $@

と書いていたのを、

%.html: %.slim
    bundle exec slimrb $< -p -r slim/include > $@

に修正。

というわけで死ぬほど久しぶりにウェブの更新。VPSのgitが古い。IUSからインストールする前に、とりあえずsudo yum updateだけ。

sudo yum update
sudo yum -y install https://repo.ius.io/ius-release-el7.rpm
$ sudo yum list  |grep git2
git236.x86_64                            2.36.1-2.el7.ius              ius  

Gitの2.36が入れられそうだな。

sudo yum -y remove git
sudo yum install git236
$ git --version  
git version 2.36.1

よろしい。

CentOSでbundler使おうとしたらRubyが古いと怒られた。入れるにはrbenv+ruby-buildを使う必要があるらしい。面倒なのでcentos-release-sclを使う。

sudo yum -y install centos-release-scl 
sudo yum -y install rh-ruby27

以下のコマンドで一時的に有効に。

scl enable rh-ruby27 zsh 

以下でずっと有効になるはずが、コマンドがないと言われる。

$ source scl_source enable rh-ruby27 
/usr/bin/scl_source:source:63: no such file or directory: //enable
Can't source enable, skipping.

仕方ないので、直接パスを指定して実行。

source /opt/rh/rh-ruby27/enable 

これを.zshrc_mine.zshに追加。ようやくGitとRubyの新しい奴が入った。

$ bundler install
Traceback (most recent call last):
 2: from /opt/rh/rh-ruby27/root/usr/bin/bundler:23:in `<main>'
 1: from /opt/rh/rh-ruby27/root/usr/share/rubygems/rubygems.rb:296:in `activate_bin_path'
/opt/rh/rh-ruby27/root/usr/share/rubygems/rubygems.rb:277:in `find_spec_for_exe': Could not find 'bundler' (1.17.2) required by your /home/watanabe/public_html/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.17.2`

古いのか。アップデートしてもう一度。

bundle update --bundler     
bundler install

できた。

というわけで、外部資金や計算資源のページができた。YAMLのデータをslimで読み込んでHTMLに変換している。書類仕事がいっぱいある時のサーバ設定楽しい(逃避)。

物性研スパコン後期出した。

査読締め切り確認。まだ大丈夫そうだな。