-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai.cryptoplatedhover.erb
154 lines (129 loc) · 5.3 KB
/
ai.cryptoplatedhover.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Require the ERB library
require 'erb'
# Define a class to represent an article
class Article
attr_accessor :title, :source, :url, :summary, :color
def initialize(title, source, url, summary, color)
@title = title
@source = source
@url = url
@summary = summary
@color = color
end
end
# Create some sample articles from the web search results
articles = [
Article.new("The 50 Best Cryptocurrency Blogs of 2023 - Detailed.com", "Detailed.com", "^1^", "The best Cryptocurrency blogs from thousands of blogs on the web and ranked by traffic, social media followers & freshness.", "green"),
Article.new("Best Crypto Apps & Exchanges Of November 2023 – Forbes Advisor", "Forbes", "^2^", "The best crypto apps and exchanges for both new and experienced investors, based on features, fees, security, and more.", "red"),
Article.new("16 Best Cryptocurrency Blogs 2024 – Must Read! - Cryptalker", "Cryptalker", "^3^", "A list of the 16 best crypto blogs to follow for the latest news, insights, and analysis on the cryptocurrency world.", "blue"),
Article.new("100 Best Cryptocurrency Blogs and Websites in 2023 - Feedspot Blog", "Feedspot", "^4^", "A comprehensive list of the top cryptocurrency blogs and websites on the web, updated daily and ranked by popularity.", "yellow")
]
# Define a method to draw a horizontal line with ASCII art
def draw_line(length)
"+" + "-" * length + "+"
end
# Define a method to draw a cell with ASCII art
def draw_cell(content, length)
"|" + content.ljust(length) + "|"
end
# Define a method to draw a table with ASCII art
def draw_table(data, headers, length)
# Draw the top line
puts draw_line(length)
# Draw the header row
headers.each do |header|
print draw_cell(header, length / headers.size)
end
puts
# Draw the separator line
puts draw_line(length)
# Draw the data rows
data.each do |row|
row.each do |cell|
print draw_cell(cell, length / row.size)
end
puts
end
# Draw the bottom line
puts draw_line(length)
end
# Define a method to create a cell with SVG
def create_cell(content, x, y, width, height, color)
# Create a rectangle element
rect = "<rect x='#{x}' y='#{y}' width='#{width}' height='#{height}' fill='#{color}' stroke='black'/>"
# Create a text element
text = "<text x='#{x + width / 2}' y='#{y + height / 2}' text-anchor='middle' dominant-baseline='central' fill='white'>#{content}</text>"
# Return the SVG elements
rect + text
end
# Define a method to create a table with SVG
def create_table(data, headers, width, height)
# Calculate the cell size
cell_width = width / headers.size
cell_height = height / (data.size + 1)
# Create an array to store the SVG elements
svg = []
# Create the header cells
headers.each_with_index do |header, i|
svg << create_cell(header, i * cell_width, 0, cell_width, cell_height, "black")
end
# Create the data cells
data.each_with_index do |row, j|
row.each_with_index do |cell, i|
svg << create_cell(cell, i * cell_width, (j + 1) * cell_height, cell_width, cell_height, row[-1])
end
end
# Return the SVG elements as a string
svg.join("\n")
end
# Define a method to create a button with SVG and ASCII art
def create_button(text, x, y, width, height, color, hover_color)
# Create a rectangle element with a hover effect
rect = "<rect x='#{x}' y='#{y}' width='#{width}' height='#{height}' fill='#{color}' stroke='black'>
<animate attributeName='fill' attributeType='XML' from='#{color}' to='#{hover_color}' begin='mouseover' end='mouseout' dur='0.5s' fill='freeze'/>
</rect>"
# Create a text element
text = "<text x='#{x + width / 2}' y='#{y + height / 2}' text-anchor='middle' dominant-baseline='central' fill='white'>#{text}</text>"
# Create an ASCII art representation of the button
ascii = "[#{text}]"
# Return the SVG and ASCII elements as a string
rect + text + ascii
end
# Define an ERB template to embed Ruby code in HTML
template = <<-HTML
<!DOCTYPE html>
<html>
<head>
<title>Cryptocurrency Articles Reminder</title>
</head>
<body>
<h1>Cryptocurrency Articles Reminder</h1>
<p>This is an example of using ERB to embed Ruby code in HTML.</p>
<p>The table below is generated by studying articles about cryptocurrency from sources linked to or on popular exchange blogs, including other investments, and outputting that information as an HTML table drawn in SVG vectors and ASCII art, depending on the text color.</p>
<div id="svg-table">
<svg width="800" height="300" xmlns="http://www.w3.org/2000/svg">
<%= create_table(articles.map { |a| [a.title, a.source, a.url, a.summary, a.color] }, ["Title", "Source", "URL", "Summary", "Color"], 800, 300) %>
</svg>
</div>
<div id="ascii-table">
<pre>
<%= draw_table(articles.map { |a| [a.title, a.source, a.url, a.summary, a.color] }, ["Title", "Source", "URL", "Summary", "Color"], 80) %>
</pre>
</div>
<div id="svg-button">
<svg width="200" height="50" xmlns="http://www.w3.org/2000/svg">
<%= create_button("More Articles", 0, 0, 200, 50, "green", "blue") %>
</svg>
</div>
<div id="ascii-button">
<pre>
<%= create_button("More Articles", 0, 0, 200, 50, "green", "blue") %>
</pre>
</div>
</body>
</html>
HTML
# Create an ERB object from the template
erb = ERB.new(template)
# Print the result of the ERB evaluation
puts erb.result