Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
[Roppongi.rb#20] groverのコードをなんとなく読んでみた
Search
ryichk
July 11, 2024
Programming
210
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
[Roppongi.rb#20] groverのコードをなんとなく読んでみた
Roppongi.rb#20
でLTしたスライドです!
ryichk
July 11, 2024
More Decks by ryichk
See All by ryichk
OAuth2.0、JWT 入門 / Introduction to OAuth2.0 and JWT
ryichk
0
110
「入門 監視」を読んでみた / I read "Practical Monitoring"
ryichk
0
110
Lambdalithという選択肢を検討中 / Considering the option of Lambdalith
ryichk
1
710
Other Decks in Programming
See All in Programming
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
270
最近”作らせてる” ローカルAIアプリの話
akit37
0
480
Kotlinの15年とServer-Side Kotlin
n_takehata
1
160
APNsからLive Activityを開始する話
yumnumm
0
170
ジョジョの世界をXRで再現する
mofurune
0
180
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
300
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
0
150
Agents on Rails - Rails at Scale 2026
irinanazarova
0
570
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
270
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
180
気持ちぃ〜角丸 Squircle
ryu1013
0
320
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
How to Talk to Developers About Accessibility
jct
2
580
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Ethics towards AI in product and experience design
skipperchong
2
440
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Building an army of robots
kneath
307
47k
Into the Great Unknown - MozCon
thekraken
41
2.8k
Evolving SEO for Evolving Search Engines
ryanjones
0
330
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
490
Build your cross-platform service in a week with App Engine
jlugia
234
19k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
67k
Transcript
groverのコードを なんとなく読んでみた Ryo Ichiki
自己紹介 3社目:HRテック系ベンチャー(現在) Ruby, TypeScript 2社目:不動産テック系ベンチャー Ruby, PHP, JavaScript 1社目:小さい受託開発会社 C#
大学:理学部(情報系ではない) C, R, Ruby GitHub:ryichk X:@ryichk_dev
groverとは? HTMLをPDFやPNG画像、JPEG画像に変換できるgemです。 内部でPuppeteerとChromiumを使って変換しています。 PuppeteerはChromeを操作するNode.jsのライブラリです。 なのでgroverを使うためにはNode.jsの環境も必要です。 https://github.com/Studiosity/grover
groverを知ったきっかけ HTMLをPDFに変換するメジャーなgemとしてwicked_pdfがあります。 このwicked_pdfを別のgemにリプレイスする必要がありました。 wicked_pdfは内部でwkhtmltopdfというライブラリ(gemではない)を使っています。 wkhtmltopdfは2023/1/2にアーカイブされておりメンテが終了している状態です。 EC2のOSをAmazon Linux 2023へアップグレードした際に動かなくなるリスクがあり、仮 に動いたとしても...
groverの他にも候補がありました ・ferrum ・prawn
Groverの使い方 https://github.com/Studiosity/grover?tab=readme-ov-file#usage
Railsで使う場合 https://github.com/Studiosity/grover?tab=readme-ov-file#from-a-view-template
Grover#to_pdf を見ていく
Grover#to_pdf 〜
Grover::Processor#convert
Grover::Processor#convert
Grover::Processor#spawn_process
Open3.#popen3について popen3(*cmd) -> [IO, IO, IO, Thread] 外部プログラムcmdを実行し、そのプロセスの標準入力、標準出力、標準エラー出力に 接続されたパイプと実行したプロセスを待つためのスレッドを4要素の配列で返す。 https://docs.ruby-lang.org/ja/latest/method/Open3/m/popen3.html
Open3.#popen3 を使って別プロセスを立ち上げ、 Node.js 経由で processor.cjs を実行している
Grover::Processor#convert
Grover::Processor#ensure_packages_are_initiated
Grover::Processor#ensure_packages_are_initiated 要はNode.jsのプロセスが問題なく起 動しているか確認している
Grover::Processor#convert
Grover::Processor#call_js_method
Grover::Processor#call_js_method
Grover::Processor#call_js_method つまり、 processor.cjsに method, url_or_html, options を渡している method = :pdf
processor.cjs(超ざっくり) 1. puppeteerでChromeブラウザを起動し、接続する 2. 引数で渡されたURL or HTML文字列をブラウザで読み込む 3. puppeteerのPage.pdf()メソッドを実行 a.
読み込んだページの PDFを生成する 4. 生成されたPDFを標準出力に書き出す 5. Chromeブラウザの接続を閉じて終了
まとめ・感想 ・groverはpuppeteerというNode.jsのライブラリを Ruby経由で無理やり操作するためのgemという感じ ・やっていることはシンプル。 ・だけど細かく見ていくと複雑 ・Ruby経由でNode.jsのライブラリを実行できるなら他にも色々できそう (Node.jsに限らず)
ご清聴ありがとうございました