From 4c6e2d435d61a2f25b9e6da43545b2d1ac2fe93f Mon Sep 17 00:00:00 2001 From: gintama91 Date: Tue, 17 Oct 2023 13:51:52 +0530 Subject: [PATCH] code --- examples/code.rb | 3 ++ lacci/lib/shoes/drawables.rb | 1 + lacci/lib/shoes/drawables/codes.rb | 14 ++++++++ lib/scarpe/wv.rb | 21 ++++++++++-- lib/scarpe/wv/codes.rb | 13 +++++++ .../lib/scarpe/components/calzini/misc.rb | 34 +++++++++++++++++++ .../lib/scarpe/components/html.rb | 30 ++++++++++++++-- 7 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 examples/code.rb create mode 100644 lacci/lib/shoes/drawables/codes.rb create mode 100644 lib/scarpe/wv/codes.rb diff --git a/examples/code.rb b/examples/code.rb new file mode 100644 index 000000000..b87eb503b --- /dev/null +++ b/examples/code.rb @@ -0,0 +1,3 @@ +Shoes.app do + codes "Shoes.app do\n para 'Hello, world!'\nend" +end diff --git a/lacci/lib/shoes/drawables.rb b/lacci/lib/shoes/drawables.rb index 760e883bf..db8dfed07 100644 --- a/lacci/lib/shoes/drawables.rb +++ b/lacci/lib/shoes/drawables.rb @@ -28,3 +28,4 @@ require "shoes/drawables/span" require "shoes/drawables/video" require "shoes/drawables/progress" +require "shoes/drawables/codes" diff --git a/lacci/lib/shoes/drawables/codes.rb b/lacci/lib/shoes/drawables/codes.rb new file mode 100644 index 000000000..97ace4063 --- /dev/null +++ b/lacci/lib/shoes/drawables/codes.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Shoes + class Codes < Shoes::Drawable + shoes_styles :text + + def initialize(text) + @text = text + super + + create_display_drawable + end + end +end diff --git a/lib/scarpe/wv.rb b/lib/scarpe/wv.rb index 601a8367b..17b42957a 100644 --- a/lib/scarpe/wv.rb +++ b/lib/scarpe/wv.rb @@ -38,9 +38,23 @@ module Scarpe::Webview # Fun trivia: listing the full set of available fonts is a fingerprinting attack, so it's not # available from JS. These are all commonly available web fonts, though. -Shoes::FONTS.concat ["Helvetica", "Arial", "Arial Black", "Verdana", "Tahoma", "Trebuchet MS", - "Impact", "Gill Sans", "Times New Roman", "Georgia", "Palatino", "Baskerville", - "Courier", "Lucida", "Monaco"] +Shoes::FONTS.concat [ + "Helvetica", + "Arial", + "Arial Black", + "Verdana", + "Tahoma", + "Trebuchet MS", + "Impact", + "Gill Sans", + "Times New Roman", + "Georgia", + "Palatino", + "Baskerville", + "Courier", + "Lucida", + "Monaco", +] if ENV["SHOES_SPEC_TEST"] require_relative "shoes_spec" @@ -81,3 +95,4 @@ module Scarpe::Webview require_relative "wv/check" require_relative "wv/progress" require_relative "wv/arrow" +require_relative "wv/codes" diff --git a/lib/scarpe/wv/codes.rb b/lib/scarpe/wv/codes.rb new file mode 100644 index 000000000..abb023210 --- /dev/null +++ b/lib/scarpe/wv/codes.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Scarpe::Webview + class Codes < Drawable + def initialize(properties) + super + end + + def element + render("codes") + end + end +end diff --git a/scarpe-components/lib/scarpe/components/calzini/misc.rb b/scarpe-components/lib/scarpe/components/calzini/misc.rb index 91b7af2ba..26f571a11 100644 --- a/scarpe-components/lib/scarpe/components/calzini/misc.rb +++ b/scarpe-components/lib/scarpe/components/calzini/misc.rb @@ -128,4 +128,38 @@ def list_box_style(props) styles end + + def codes_element(props) + HTML.render do |h| + h.pre(id: html_id, style: code_pre_style(props)) do + h.code do + props["text"] + end + end + end + end + + def code_pre_style(props) + styles = drawable_style(props) + styles["background-color"] = "#2E2E2E" + styles["color"] = "#FFFFFF" + styles["font-family"] = "'Courier New', monospace" + styles["max-width"] = "80vw" + styles["max-height"] = "60vh" + styles["overflow"] = "auto" + styles["padding"] = "20px" + styles["border-radius"] = "10px" + styles["box-shadow"] = "0 0 15px rgba(0, 0, 0, 0.4)" + styles["border"] = "2px solid #444" + styles["line-height"] = "1.4" + + styles + end + + def code_code_style(props) + styles = drawable_style(props) + styles["background-color"] = "#2E2E2E" + + styles + end end diff --git a/scarpe-components/lib/scarpe/components/html.rb b/scarpe-components/lib/scarpe/components/html.rb index 9b121ec78..be13eabcf 100644 --- a/scarpe-components/lib/scarpe/components/html.rb +++ b/scarpe-components/lib/scarpe/components/html.rb @@ -1,8 +1,34 @@ # frozen_string_literal: true class Scarpe::Components::HTML - - CONTENT_TAGS = [:div, :p, :button, :ul, :li, :textarea, :a, :video, :strong, :style, :progress, :em, :code, :defs, :marker, :u, :line, :span, :svg, :h1, :h2, :h3, :h4, :h5].freeze + CONTENT_TAGS = [ + :div, + :p, + :button, + :ul, + :li, + :textarea, + :a, + :video, + :strong, + :style, + :progress, + :em, + :code, + :defs, + :marker, + :u, + :line, + :span, + :svg, + :h1, + :h2, + :h3, + :h4, + :h5, + :pre, + :code, + ].freeze VOID_TAGS = [:input, :img, :polygon, :source, :link, :path, :rect].freeze TAGS = (CONTENT_TAGS + VOID_TAGS).freeze