Class: Jekyll::CryptoDonations::DonationsTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::CryptoDonations::DonationsTag
- Defined in:
- lib/jekyll-crypto-donations.rb
Overview
describe crypto_donations % tag content
Constant Summary collapse
- CRYPTO_CURRENCIES =
{ btc: { name: "Bitcoin", ticker: "BTC" }, eth: { name: "Ethereum", ticker: "ETH" }, usdt: { name: "Tether", ticker: "USDT TRC-20" } }.freeze
Instance Attribute Summary collapse
-
#btc_address ⇒ Object
readonly
rubocop:disable Metrics/ClassLength.
-
#eth_address ⇒ Object
readonly
rubocop:disable Metrics/ClassLength.
-
#usdt_address ⇒ Object
readonly
rubocop:disable Metrics/ClassLength.
Instance Method Summary collapse
- #btc_html ⇒ Object
- #btc_js ⇒ Object
- #closing_html ⇒ Object
- #closing_js ⇒ Object
- #currency_html(currency_ticker, address) ⇒ Object
- #eth_html ⇒ Object
- #eth_js ⇒ Object
-
#initialize(tag_name, text, tokens) ⇒ DonationsTag
constructor
A new instance of DonationsTag.
- #opening_html ⇒ Object
- #render(context) ⇒ Object
- #site_config(context) ⇒ Object
- #usdt_html ⇒ Object
- #usdt_js ⇒ Object
Constructor Details
#initialize(tag_name, text, tokens) ⇒ DonationsTag
Returns a new instance of DonationsTag.
19 20 21 22 |
# File 'lib/jekyll-crypto-donations.rb', line 19 def initialize(tag_name, text, tokens) super @text = text end |
Instance Attribute Details
#btc_address ⇒ Object (readonly)
rubocop:disable Metrics/ClassLength
11 12 13 |
# File 'lib/jekyll-crypto-donations.rb', line 11 def btc_address @btc_address end |
#eth_address ⇒ Object (readonly)
rubocop:disable Metrics/ClassLength
11 12 13 |
# File 'lib/jekyll-crypto-donations.rb', line 11 def eth_address @eth_address end |
#usdt_address ⇒ Object (readonly)
rubocop:disable Metrics/ClassLength
11 12 13 |
# File 'lib/jekyll-crypto-donations.rb', line 11 def usdt_address @usdt_address end |
Instance Method Details
#btc_html ⇒ Object
92 93 94 95 96 |
# File 'lib/jekyll-crypto-donations.rb', line 92 def btc_html return "" unless btc_address currency_html(:btc, btc_address) end |
#btc_js ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/jekyll-crypto-donations.rb', line 110 def btc_js return "" unless btc_address " const btcDonations = await getDonations('btc', '\#{btc_address}');\n document.getElementById('jekyll-crypto-donations_btc-total').innerText = `Total received: ${btcDonations} BTC`;\n JS\nend\n" |
#closing_html ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/jekyll-crypto-donations.rb', line 153 def closing_html " </div>\n <script type=\"module\">\n import { getDonations } from '/assets/js/crypto-donations/crypto-donations.js';\n document.addEventListener('DOMContentLoaded', function () {\n document.querySelectorAll('.jekyll-crypto-donations__item').forEach((item) => {\n item.querySelector('.jekyll-crypto-donations__crypto-btn-copy').addEventListener('click', () => {\n const code = item.querySelector('.jekyll-crypto-donations__crypto-code');\n navigator.clipboard.writeText(code.innerText);\n code.classList.add('jekyll-crypto-donations__crypto-code--is-copied');\n setTimeout(() => {\n code.classList.remove('jekyll-crypto-donations__crypto-code--is-copied');\n }, 1500);\n });\n\n item.querySelector('.jekyll-crypto-donations__crypto-btn-qr').addEventListener('click', () => {\n item.querySelector('.jekyll-crypto-donations__crypto').classList.toggle('jekyll-crypto-donations__crypto--show-qr');\n });\n });\n });\n\n document.addEventListener('DOMContentLoaded', async () => {\n HTML\nend\n" |
#closing_js ⇒ Object
179 180 181 182 183 184 |
# File 'lib/jekyll-crypto-donations.rb', line 179 def closing_js " });\n </script>\n JS\nend\n" |
#currency_html(currency_ticker, address) ⇒ Object
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 |
# File 'lib/jekyll-crypto-donations.rb', line 24 def currency_html(currency_ticker, address) currency = CRYPTO_CURRENCIES[currency_ticker] " <div class=\"jekyll-crypto-donations__item\">\n <span class=\"jekyll-crypto-donations__crypto-name\">\#{currency[:name]} (\#{currency[:ticker]})</span>\n <div class=\"jekyll-crypto-donations__crypto\">\n <div class=\"jekyll-crypto-donations__crypto-value\">\n <div class=\"jekyll-crypto-donations__crypto-code\">\n <span>\#{address}</span>\n </div>\n <div class=\"jekyll-crypto-donations__crypto-buttons\">\n <button class=\"jekyll-crypto-donations__crypto-btn-copy\">\n <svg id=\"svg\" fill=\"#ededed\" stroke=\"#ededed\" width=\"20\" height=\"20\" version=\"1.1\" viewBox=\"144 144 512 512\" xmlns=\"http://www.w3.org/2000/svg\" stroke-width=\"20\">\n <g id=\"IconSvg_bgCarrier\" stroke-width=\"0\"></g>\n <g id=\"IconSvg_tracerCarrier\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke=\"#CCCCCC\" stroke-width=\"0\">\n <g xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"m458.74 466.8h123.13 17.23c5.4414 0 10.078-4.6367 10.078-10.078v-86.957-139.15-31.84c0-5.4414-4.6367-10.078-10.078-10.078h-87.359-138.95-31.641c-5.4414 0-10.078 4.6367-10.078 10.078v126.66 17.938c0 13 20.152 13 20.152 0v-126.66-17.938c-3.3242 3.3242-6.75 6.75-10.078 10.078h87.359 138.95 31.641c-3.3242-3.3242-6.75-6.75-10.078-10.078v86.957 139.15 31.84l10.078-10.078h-123.13-17.23c-12.992 0.003906-12.992 20.156 0.003907 20.156z\"></path>\n <path d=\"m458.74 591.14h-86.957-139.15-31.84l10.078 10.078v-86.957-139.15-31.84c-3.3242 3.3242-6.75 6.75-10.078 10.078h86.957 139.15 31.84c-3.3242-3.3242-6.75-6.75-10.078-10.078v86.957 139.15 31.84c0 13 20.152 13 20.152 0v-86.957-139.15-31.84c0-5.4414-4.6367-10.078-10.078-10.078h-86.957-139.15-31.84c-5.4414 0-10.078 4.6367-10.078 10.078v86.957 139.15 31.84c0 5.4414 4.6367 10.078 10.078 10.078h86.957 139.15 31.84c13.004-0.003906 13.004-20.156 0.003907-20.156z\"></path>\n </g>\n </g>\n <g id=\"IconSvg_iconCarrier\">\n <g xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"m458.74 466.8h123.13 17.23c5.4414 0 10.078-4.6367 10.078-10.078v-86.957-139.15-31.84c0-5.4414-4.6367-10.078-10.078-10.078h-87.359-138.95-31.641c-5.4414 0-10.078 4.6367-10.078 10.078v126.66 17.938c0 13 20.152 13 20.152 0v-126.66-17.938c-3.3242 3.3242-6.75 6.75-10.078 10.078h87.359 138.95 31.641c-3.3242-3.3242-6.75-6.75-10.078-10.078v86.957 139.15 31.84l10.078-10.078h-123.13-17.23c-12.992 0.003906-12.992 20.156 0.003907 20.156z\"></path>\n <path d=\"m458.74 591.14h-86.957-139.15-31.84l10.078 10.078v-86.957-139.15-31.84c-3.3242 3.3242-6.75 6.75-10.078 10.078h86.957 139.15 31.84c-3.3242-3.3242-6.75-6.75-10.078-10.078v86.957 139.15 31.84c0 13 20.152 13 20.152 0v-86.957-139.15-31.84c0-5.4414-4.6367-10.078-10.078-10.078h-86.957-139.15-31.84c-5.4414 0-10.078 4.6367-10.078 10.078v86.957 139.15 31.84c0 5.4414 4.6367 10.078 10.078 10.078h86.957 139.15 31.84c13.004-0.003906 13.004-20.156 0.003907-20.156z\"></path>\n </g>\n </g>\n </svg>\n </button>\n <button class=\"jekyll-crypto-donations__crypto-btn-qr\">\n <svg id=\"svg\" fill=\"#ededed\" stroke=\"#ededed\" width=\"20\" height=\"20\" version=\"1.1\" viewBox=\"144 144 512 512\" xmlns=\"http://www.w3.org/2000/svg\" stroke-width=\"0\">\n <g id=\"IconSvg_bgCarrier\" stroke-width=\"0\"></g>\n <g id=\"IconSvg_tracerCarrier\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke=\"#CCCCCC\" stroke-width=\"0\">\n <g xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"m379.01 588.93h-167.94v-167.93h167.94zm-125.95-41.984h83.969v-83.965h-83.969z\"></path>\n <path d=\"m588.93 379.01h-167.93v-167.94h167.94zm-125.95-41.984h83.969l-0.003906-83.969h-83.965z\"></path>\n <path d=\"m379.01 379.01h-167.94v-167.94h167.94zm-125.95-41.984h83.969v-83.969h-83.969z\"></path>\n <path d=\"m588.93 588.93h-83.969v-41.984h41.984v-41.984h41.984z\"></path>\n <path d=\"m462.98 588.93h-41.984v-83.969h41.984v-41.98h41.98v83.965h-41.98z\"></path>\n <path d=\"m420.99 420.99h41.984v41.984h-41.984z\"></path>\n <path d=\"m504.96 420.99h83.969v41.984h-83.969z\"></path>\n </g>\n </g>\n <g id=\"IconSvg_iconCarrier\">\n <g xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"m379.01 588.93h-167.94v-167.93h167.94zm-125.95-41.984h83.969v-83.965h-83.969z\"></path>\n <path d=\"m588.93 379.01h-167.93v-167.94h167.94zm-125.95-41.984h83.969l-0.003906-83.969h-83.965z\"></path>\n <path d=\"m379.01 379.01h-167.94v-167.94h167.94zm-125.95-41.984h83.969v-83.969h-83.969z\"></path>\n <path d=\"m588.93 588.93h-83.969v-41.984h41.984v-41.984h41.984z\"></path>\n <path d=\"m462.98 588.93h-41.984v-83.969h41.984v-41.98h41.98v83.965h-41.98z\"></path>\n <path d=\"m420.99 420.99h41.984v41.984h-41.984z\"></path>\n <path d=\"m504.96 420.99h83.969v41.984h-83.969z\"></path>\n </g>\n </g>\n </svg>\n </button>\n <div class=\"jekyll-crypto-donations__crypto-total-received\">\n <span id=\"jekyll-crypto-donations_\#{currency_ticker}-total\">Loading...</span>\n </div>\n </div>\n </div>\n <div class=\"jekyll-crypto-donations__crypto-image-qr\">\n <img alt=\"\" width=\"150px\" heght=\"150px\" src=\"https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=\#{address}\">\n </div>\n </div>\n </div>\n HTML\nend\n" |
#eth_html ⇒ Object
98 99 100 101 102 |
# File 'lib/jekyll-crypto-donations.rb', line 98 def eth_html return "" unless eth_address currency_html(:eth, eth_address) end |
#eth_js ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/jekyll-crypto-donations.rb', line 119 def eth_js return "" unless eth_address " const ethDonations = await getDonations('eth', '\#{eth_address}');\n document.getElementById('jekyll-crypto-donations_eth-total').innerText = `Total received: ${ethDonations} ETH`;\n JS\nend\n" |
#opening_html ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/jekyll-crypto-donations.rb', line 144 def opening_html " <div id=\"jekyll-crypto-donations\">\n <div class=\"jekyll-crypto-donations__description\">\n <span>\#{@text}</span>\n </div>\n HTML\nend\n" |
#render(context) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/jekyll-crypto-donations.rb', line 186 def render(context) site_config(context) return if btc_address.nil? && eth_address.nil? && usdt_address.nil? content = opening_html content += btc_html content += eth_html content += usdt_html content += closing_html content += btc_js content += eth_js content += usdt_js content += closing_js content end |
#site_config(context) ⇒ Object
137 138 139 140 141 142 |
# File 'lib/jekyll-crypto-donations.rb', line 137 def site_config(context) site_config = context.registers.fetch(:site).config @btc_address = site_config.dig("crypto_donations", "btc_address") @eth_address = site_config.dig("crypto_donations", "eth_address") @usdt_address = site_config.dig("crypto_donations", "usdt_address") end |
#usdt_html ⇒ Object
104 105 106 107 108 |
# File 'lib/jekyll-crypto-donations.rb', line 104 def usdt_html return "" unless usdt_address currency_html(:usdt, usdt_address) end |
#usdt_js ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/jekyll-crypto-donations.rb', line 128 def usdt_js return "" unless usdt_address " const usdtDonations = await getDonations('usdt', '\#{usdt_address}');\n document.getElementById('jekyll-crypto-donations_usdt-total').innerText = `Total received: ${usdtDonations} USDT`;\n JS\nend\n" |