Has anyone ever tried this kind of thing before?
[%w[File Edit View Menu], %w[PHP Ruby Javascript Python], ["The wonderful
frog named Joe ran", "It did?"]].append(new).website("Page") {
"body { margin:0px;} " + \
"body div { text-align: center; padding: 10px; margin: 0px; border: 0px
solid black; margin: 0px; background-color: #EEEEEE; color: blue; }" + \
"body > div:nth-child(1) { text-align: left; } " + \
"body > div:nth-child(2) > span { padding: 30px 30px 0px 0px; } " + \
"body span { margin: 3px; }"
}
···
---------------------------------
class Array
@@i = 0
@@n = 0
def inspect(id_list=[])
def add_to_text elem, element
@@n += 1
s="\n" + "\t" * (@@i * 3)
text = ([String,Integer].include?(element.class)?element:
element.inspect)
"#{s}<#{elem} class=\"#{element.class} #{element.class.to_s.downcase}
depth#{@@i}\" id=\"#{text[0..500].gsub(/[^a-zA-Z$_]/,
'')}\">#{text}#{s}</#{elem}>" + "\n" ; end
text = ""
@@i += 1
elem_ = (self.class) == Array ? "div" : "span"
each do |element|
elem = element.class == Array ? "div" : "span"
text<<add_to_text(elem, element)
end
@@i -= 1
text
end
def website(title)
puts <<PAGE
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>#{title}</title>
<style type="text/css">
#{yield}
</style>
</head>
<!-- Body -->
<body>
#{inspect}
</body>
</html>
PAGE
end
end
words = File.read("/usr/share/dict/words").split("\n").shuffle[..500].map
&:downcase
i = 0
new = []
while i < 500
new.push words[i..i+4].to_a
i += 4
end
[%w[File Edit View Menu], %w[PHP Ruby Javascript Python], ["The wonderful
frog named Joe ran", "It did?"]].append(new).website("Page") {
"body { margin:0px;} " + \
"body div { text-align: center; padding: 10px; margin: 0px; border: 0px
solid black; margin: 0px; background-color: #EEEEEE; color: blue; }" + \
"body > div:nth-child(1) { text-align: left; } " + \
"body > div:nth-child(2) > span { padding: 30px 30px 0px 0px; } " + \
"body span { margin: 3px; }"
}
--------------------------------------------------------------------
to_html (1.43 KB)
Hi!
Seems, i'm not up-to-date:
Can you tell us, how this works (which libs/tools do you use?)
What is the part of each?
thank you, Opti
···
Am 22.10.21 um 06:23 schrieb Gregory Cohen:
Has anyone ever tried this kind of thing before?
[%w[File Edit View Menu], %w[PHP Ruby Javascript Python], ["The
wonderful frog named Joe ran", "It did?"]].append(new).website("Page") {
"body { margin:0px;} " + \
"body div { text-align: center; padding: 10px; margin: 0px; border:
0px solid black; margin: 0px; background-color: #EEEEEE; color: blue;
}" + \
"body > div:nth-child(1) { text-align: left; } " + \
"body > div:nth-child(2) > span { padding: 30px 30px 0px 0px; } " + \
"body span { margin: 3px; }"
}
---------------------------------
class Array
@@i = 0
@@n = 0
def inspect(id_list=)
def add_to_text elem, element
@@n += 1
s="\n" + "\t" * (@@i * 3)
text = ([String,Integer].include?(element.class)?element:
element.inspect)
"#{s}<#{elem} class=\"#{element.class} #{element.class.to_s.downcase}
depth#{@@i}\" id=\"#{text[0..500].gsub(/[^a-zA-Z$_]/,
'')}\">#{text}#{s}</#{elem}>" + "\n" ; end
text = ""
@@i += 1
elem_ = (self.class) == Array ? "div" : "span"
each do |element|
elem = element.class == Array ? "div" : "span"
text<<add_to_text(elem, element)
end
@@i -= 1
text
end
def website(title)
puts <<PAGE
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>#{title}</title>
<style type="text/css">
#{yield}
</style>
</head>
<!-- Body -->
<body>
#{inspect}
</body>
</html>
PAGE
end
words =
File.read("/usr/share/dict/words").split("\n").shuffle[..500].map
&:downcase
i = 0
new =
while i < 500
new.push words[i..i+4].to_a
i += 4
end
[%w[File Edit View Menu], %w[PHP Ruby Javascript Python], ["The
wonderful frog named Joe ran", "It did?"]].append(new).website("Page") {
"body { margin:0px;} " + \
"body div { text-align: center; padding: 10px; margin: 0px; border:
0px solid black; margin: 0px; background-color: #EEEEEE; color: blue;
}" + \
"body > div:nth-child(1) { text-align: left; } " + \
"body > div:nth-child(2) > span { padding: 30px 30px 0px 0px; } " + \
"body span { margin: 3px; }"
}
hmdne
(hmdne)
3
You may take a look at Paggio:
We use this library in Opal-Browser to provide HTML and CSS generation DSLs
···
On 10/22/21 06:23, Gregory Cohen wrote:
Has anyone ever tried this kind of thing before?
[%w[File Edit View Menu], %w[PHP Ruby Javascript Python], ["The wonderful frog named Joe ran", "It did?"]].append(new).website("Page") {
"body { margin:0px;} " + \
"body div { text-align: center; padding: 10px; margin: 0px; border: 0px solid black; margin: 0px; background-color: #EEEEEE; color: blue; }" + \
"body > div:nth-child(1) { text-align: left; } " + \
"body > div:nth-child(2) > span { padding: 30px 30px 0px 0px; } " + \
"body span { margin: 3px; }"
}
---------------------------------
class Array
@@i = 0
@@n = 0
def inspect(id_list=)
def add_to_text elem, element
@@n += 1
s="\n" + "\t" * (@@i * 3)
text = ([String,Integer].include?(element.class)?element: element.inspect)
"#{s}<#{elem} class=\"#{element.class} #{element.class.to_s.downcase} depth#{@@i}\" id=\"#{text[0..500].gsub(/[^a-zA-Z$_]/, '')}\">#{text}#{s}</#{elem}>" + "\n" ; end
text = ""
@@i += 1
elem_ = (self.class) == Array ? "div" : "span"
each do |element|
elem = element.class == Array ? "div" : "span"
text<<add_to_text(elem, element)
end
@@i -= 1
text
end
def website(title)
puts <<PAGE
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>#{title}</title>
<style type="text/css">
#{yield}
</style>
</head>
<!-- Body -->
<body>
#{inspect}
</body>
</html>
PAGE
end
words = File.read("/usr/share/dict/words").split("\n").shuffle[..500].map &:downcase
i = 0
new =
while i < 500
new.push words[i..i+4].to_a
i += 4
end
[%w[File Edit View Menu], %w[PHP Ruby Javascript Python], ["The wonderful frog named Joe ran", "It did?"]].append(new).website("Page") {
"body { margin:0px;} " + \
"body div { text-align: center; padding: 10px; margin: 0px; border: 0px solid black; margin: 0px; background-color: #EEEEEE; color: blue; }" + \
"body > div:nth-child(1) { text-align: left; } " + \
"body > div:nth-child(2) > span { padding: 30px 30px 0px 0px; } " + \
"body span { margin: 3px; }"
}
--------------------------------------------------------------------
Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Hi!
Seems, i'm not up-to-date:
Can you tell us, how this works (which libs/tools do you use?)
What is the part of each?
thank you, Opti
It just works by changing the inspect method for Array