# Make an entire website in ONE LINE of Ruby code

**URL:** <https://rubytalk.org/t/make-an-entire-website-in-one-line-of-ruby-code/75634>\
**Category:** ruby-talk\
**Created:** [22 October 2021 04:23 UTC](https://rubytalk.org/t/make-an-entire-website-in-one-line-of-ruby-code/75634 "2021-10-22T04:23:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregory\_Cohen](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/gregory_cohen/32/2986_2.png) [@Gregory\_Cohen](https://rubytalk.org/u/Gregory_Cohen)\
**Post date:** [22 October 2021 04:23 UTC](https://rubytalk.org/t/make-an-entire-website-in-one-line-of-ruby-code/75634/1 "2021-10-22T04:23:34Z")

</div>

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)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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](https://rubytalk.org/uploads/short-url/eP40BQKU7tXWbKscRXGErIPHqZ6) (1.43 KB)

---

<div class="post-metadata">

**Author:** ![Die\_Optimisten](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Die\_Optimisten](https://rubytalk.org/u/Die_Optimisten)\
**Post date:** [22 October 2021 09:02 UTC](https://rubytalk.org/t/make-an-entire-website-in-one-line-of-ruby-code/75634/2 "2021-10-22T09:02:35Z")

</div>

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; }"  
> > }

---

<div class="post-metadata">

**Author:** ![hmdne](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@hmdne](https://rubytalk.org/u/hmdne)\
**Post date:** [22 October 2021 09:22 UTC](https://rubytalk.org/t/make-an-entire-website-in-one-line-of-ruby-code/75634/3 "2021-10-22T09:22:45Z")

</div>

You may take a look at Paggio:

> **[GitHub - hmdne/paggio: Ruby, HTML and CSS at war.](https://github.com/hmdne/paggio)**
>
> Ruby, HTML and CSS at war. Contribute to hmdne/paggio development by creating an account on GitHub.

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&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Gregory\_Cohen](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/gregory_cohen/32/2986_2.png) [@Gregory\_Cohen](https://rubytalk.org/u/Gregory_Cohen)\
**Post date:** [22 October 2021 13:09 UTC](https://rubytalk.org/t/make-an-entire-website-in-one-line-of-ruby-code/75634/4 "2021-10-22T13:09:38Z")

</div>

It's just one script

> **···**
>
> On Fri, Oct 22, 2021 at 5:03 AM Die Optimisten \<inform@die-optimisten.net\> wrote:
> 
> > 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  
> > \> 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&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Gregory\_Cohen](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/gregory_cohen/32/2986_2.png) [@Gregory\_Cohen](https://rubytalk.org/u/Gregory_Cohen)\
**Post date:** [22 October 2021 13:10 UTC](https://rubytalk.org/t/make-an-entire-website-in-one-line-of-ruby-code/75634/5 "2021-10-22T13:10:37Z")

</div>

> 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
