Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ほんとにあった怖い話「slimに棲むもの」

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for ydah ydah
October 25, 2023

 ほんとにあった怖い話「slimに棲むもの」

Kaigi on Rails 2023 (非公式) 前夜祭『ほんとにあった怖い話 「slimに棲むもの」』のスライド
https://andpad.connpass.com/event/297702/ #pre_kaigi_on_rails_2023

Avatar for ydah

ydah

October 25, 2023
Tweet

More Decks by ydah

Other Decks in Programming

Transcript

  1. ほんとに 怖い話 あ つ た Kaigi on Rails 2023 (非公式)

    前夜祭 2023年10月25日 (水) 高田 雄大(本名) 発表者
  2. ɾ Name: Yudai Takada ɾ GitHub: @ydah / X: @ydah_

    ɾ Software Engineer at ANDPAD, Inc. ɾ Member of RuboCop RSpec team ɾ Member of Ruby Kansai ɾ Loves beer and heavy metal/hardcore self.inspect
  3. doctype html html head title My Slim Template body ruby:

    message = "Slim!" h1 Welcome to # { message} p This is a simple example.
  4. body p / This line won't get displayed. Neither does

    this line. /! But this one will displayed.
  5. body h1 Welcome to Slim! javascript: // JavaScript comment here

    alert("Hello, World!”); css: /* CSS comment here */ h1 { color: red; }
  6. <body> <h1>Welcome to Slim! < / h1> </ body> <script>

    / / JavaScript comment here alert("Hello, World!"); </ script> <style> / * CSS comment here * / h1 { color: red; } </ style>
  7. body h1 Welcome to Slim! javascript: / / JavaScript comment

    here alert("Hello, World!”); <body> <h1>Welcome to Slim! </ h1> </ body> <script> / / JavaScript comment here alert("Hello, World!"); </ script> slim HTML Compile
  8. body h1 Welcome to Slim! javascript: / / JavaScript comment

    here alert("Hello, World!”); <body> <h1>Welcome to Slim! < / h1> < / body> <script> alert("Hello, World!"); < / script> slim HTML slim - embedded - minify Compile
  9. module Slim class Embedded < Filter class TagEngine < Engine

    prepend Minify::Tag end class JavaScriptEngine < TagEngine prepend Minify::Javascript end ennd
  10. module Slim class Embedded < Filter module Minify module Javascript

    include Tag def on_slim_embedded(engine, body, attrs) mini fi ed_body = minify(body) super(engine, mini fi ed_body, attrs) end ennnnd
  11. h1 #{ calc_sugoi_keisan(3, 4)} h1 #{ calc_sugoi_keisan(1, 2)} ruby: def

    calc_sugoi_keisan(a, b) a + b end index.slim show.slim ᶃ ᶄ
  12. h1 #{ calc_sugoi_keisan(3, 4)} h1 #{ calc_sugoi_keisan(1, 2)} ruby: def

    calc_sugoi_keisan(a, b) a + b end index.slim show.slim ᶃ ᶄ NoMethodError ✅
  13. h1 #{ calc_sugoi_keisan(1, 2)} ruby: def calc_sugoi_keisan(a, b) a +

    b end h1 #{ calc_sugoi_keisan(3, 4)} index.slim show.slim ᶃ ᶄ
  14. h1 #{ calc_sugoi_keisan(1, 2)} ruby: def calc_sugoi_keisan(a, b) a +

    b end h1 #{ calc_sugoi_keisan(3, 4)} index.slim show.slim ᶃ ᶄ ✅ ✅
  15. spec/f i xtures/dummy.slim:1 : 5 : F : Lint/Syntax: unexpected

    token tCOLON (Using Ruby 2.7 parser; conf i gure using TargetRubyVersion parameter, under AllCops) ruby: ^ 4MJN͸3VCZͰ͸ͳ͍ͷͰɺ3VCP$PQͰ͸ղ ੳෆՄɻ4ZOUBY&SSPSʹͳΔɻ ͦΕ͸ͦ͏
  16. html ruby: if File.exists?("foo.txt") message = "Yay!" else message =

    "Nooo!" end h1 #{ message} ੾Γग़ͯ͠3VCP$PQʹ౉ͯ͠ ղੳͯ͠΋Β͏
  17. html ruby: if File.exists?("foo.txt") message = "Yay!" else message =

    "Nooo!" end h1 # { message} if File.exists?("foo.txt") message = "Yay!" else message = "Nooo!" end Extract & Calc offset Slim Code Offset
  18. ❯ slimembedcop dummy.slim Inspecting 1 f i le W Offenses:

    dummy.slim:3 : 8 : W : [Correctable] Lint/ DeprecatedClassMethods: File.exists? is deprecated in favor of File.exist ?. if File.exists?("foo.txt") ^^^^^^^^^^^^
  19. end