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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
100
「入門 監視」を読んでみた / I read "Practical Monitoring"
ryichk
0
100
Lambdalithという選択肢を検討中 / Considering the option of Lambdalith
ryichk
1
700
Other Decks in Programming
See All in Programming
wkhtmltopdfの次どうするか問題2026
willnet
1
300
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
4
3k
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken
2
170
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.3k
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
420
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
260
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
490
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
290
一人だけ、Kiroが静止する日
hideg
0
110
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
300
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
140
iOSDC2026登壇資料.pdf
riofujimon
0
160
Featured
See All Featured
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.9k
Designing Powerful Visuals for Engaging Learning
tmiket
1
550
Odyssey Design
rkendrick25
PRO
2
810
GraphQLとの向き合い方2022年版
quramy
50
15k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Utilizing Notion as your number one productivity tool
mfonobong
4
590
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.9k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
300
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
300
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Prompt Engineering for Job Search
mfonobong
0
450
Agile that works and the tools we love
rasmusluckow
331
22k
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に限らず)
ご清聴ありがとうございました