Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code #418

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

code #418

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/code.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Shoes.app do
codes "Shoes.app do\n para 'Hello, world!'\nend"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noahgibbs can you explain to me the differences?

Our examples don't have much use of this historically. And the manual says it is a text fragment

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact the only examples are ours. So, I'm possibly willing to go out on a limb for this feature? WDYT?

Copy link
Collaborator

@noahgibbs noahgibbs Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main difference is that one is a text fragment, like em() or strong() or sup(). It goes inside a para. So you'd do something like this:

para "Yup, this is ", strong(em("totally")), code(" made of code"), "!"

Pavan's codes() here is a Drawable like para. It does formatting but doesn't really support other formatting inside it (unless we don't escape the HTML, but Shoes doesn't normally let you just put random HTML in places and have it format correctly.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, given that we now have the ability to add Scarpe-specific extensions, I think it should be one of those.

end
1 change: 1 addition & 0 deletions lacci/lib/shoes/drawables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
require "shoes/drawables/span"
require "shoes/drawables/video"
require "shoes/drawables/progress"
require "shoes/drawables/codes"
14 changes: 14 additions & 0 deletions lacci/lib/shoes/drawables/codes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Shoes
class Codes < Shoes::Drawable
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm when i use code it giving me superclass mismatch idk if some other gem we using has it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be weird, because it's under Shoes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get the superclass mismatch when I check out your branch. Maybe try a "git status" and see if you have any un-checked-in changes that might cause the problem?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that why this PR isn't using code as a widget (e.g.here https://github.com/scarpe-team/scarpe/blob/main/docs/static/manual.md)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we have a code TextDrawable already, called "code". So yeah, this is a bit odd - one called "codes", but also a regular Drawable not a TextDrawable.

So if you declared it as Code, not Codes, you'd get the superclass error because Code is a child of Shoes::TextDrawable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what codes does
Screenshot_20231017_144622

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noahgibbs

should i remove this? i dont think we are using code anywhwere? in examples?

Should we remove the code text drawable, and make this PR code for this part of the spec?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gintama91 btw this looks super cool :)

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really does look awesome :-)

It's true that we have no legacy examples using code(), only more recent ones. In Shoes3, looking at their source, it looks like code (grep for cCode) is a text type, so you can use it like em() inside a para(), and it's basically just monospaced like typewriter font in HTML.

If we accept this, it should definitely be renamed to replace the other code element, not add ones named codes.

shoes_styles :text

def initialize(text)
@text = text
super

create_display_drawable
end
end
end
2 changes: 2 additions & 0 deletions lib/scarpe/wv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Scarpe::Webview::Drawable < Shoes::Linkable

# 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.push(
"Helvetica",
"Arial",
Expand Down Expand Up @@ -100,3 +101,4 @@ class Scarpe::Webview::Drawable < Shoes::Linkable
require_relative "wv/check"
require_relative "wv/progress"
require_relative "wv/arrow"
require_relative "wv/codes"
13 changes: 13 additions & 0 deletions lib/scarpe/wv/codes.rb
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions scarpe-components/lib/scarpe/components/calzini/misc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,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
4 changes: 3 additions & 1 deletion scarpe-components/lib/scarpe/components/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ class Scarpe::Components::HTML
:h3,
:h4,
:h5,
:pre,
:code,
].freeze
VOID_TAGS = [:input, :img, :polygon, :source, :link, :path, :rect, :ellipse].freeze
VOID_TAGS = [:input, :img, :polygon, :source, :link, :path, :rect, :ellipse].freeze

TAGS = (CONTENT_TAGS + VOID_TAGS).freeze

Expand Down
Loading