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
デプロイ直後のレイテンシスパイクを調べたら、 Railsの仕様にたどり着いた
nhsykym
0
110
Claude Codeを組織的に動かして月400PRを実現した話
happy_ryo
0
260
Press start. Python's next generation.
willingc
PRO
3
330
Swift愛好会100回記念 第1回を振り返る
jollyjoester
0
120
Swift愛好会と私(ウホーイ) / Swift Fan Club and Uhooi
uhooi
0
150
高専キャリア LT 発表内容
crysta1221
6
5.6k
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
2.7k
Seeing Through Serverless: Observability for AWS Lambda with ADOT and CloudWatch Application Signals
seike460
PRO
1
130
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
120
スマート反転とウェブアクセシビリティ
camiha
0
180
AI × TiDD / 2026.09.05 Redmine 大阪
tokudiro
1
120
Intent as Code
shoppingjaws
4
710
Featured
See All Featured
So, you think you're a good person
axbom
PRO
2
2.1k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
560
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
240
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
210
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
520
Odyssey Design
rkendrick25
PRO
2
800
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
Ruling the World: When Life Gets Gamed
codingconduct
0
330
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Google's AI Overviews - The New Search
badams
0
1.6k
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に限らず)
ご清聴ありがとうございました