From 3065a560dda9df3b175fb6183c73034c54b6d9eb Mon Sep 17 00:00:00 2001 From: madmatvey Date: Thu, 6 Jun 2024 16:05:40 +0400 Subject: [PATCH] Initialize gem --- .github/workflows/main.yml | 27 +++++++ .gitignore | 13 ++++ .rspec | 3 + .rubocop.yml | 13 ++++ CHANGELOG.md | 5 ++ Gemfile | 12 ++++ Gemfile.lock | 10 +++ LICENSE | 10 +-- README.md | 47 ++++++++++++ Rakefile | 12 ++++ _includes/crypto_donations.html | 18 +++++ .../js/crypto-donations/crypto-donations.js | 52 ++++++++++++++ bin/console | 15 ++++ bin/setup | 8 +++ jekyll-crypto-donations.gemspec | 39 ++++++++++ lib/jekyll-crypto-donations.rb | 72 +++++++++++++++++++ .../jekyll-crypto-donations.rb | 20 ++++++ lib/jekyll-crypto-donations/version.rb | 5 ++ package-lock.json | 24 +++++++ package.json | 5 ++ sig/jekyll/crypto/donations.rbs | 8 +++ spec/jekyll/crypto/donations_spec.rb | 11 +++ spec/spec_helper.rb | 15 ++++ src/crypto-donations/crypto-donations.ts | 41 +++++++++++ tsconfig.json | 10 +++ 25 files changed, 490 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 .gitignore create mode 100644 .rspec create mode 100644 .rubocop.yml create mode 100644 CHANGELOG.md create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 README.md create mode 100644 Rakefile create mode 100644 _includes/crypto_donations.html create mode 100644 assets/js/crypto-donations/crypto-donations.js create mode 100755 bin/console create mode 100755 bin/setup create mode 100644 jekyll-crypto-donations.gemspec create mode 100644 lib/jekyll-crypto-donations.rb create mode 100644 lib/jekyll-crypto-donations/jekyll-crypto-donations.rb create mode 100644 lib/jekyll-crypto-donations/version.rb create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 sig/jekyll/crypto/donations.rbs create mode 100644 spec/jekyll/crypto/donations_spec.rb create mode 100644 spec/spec_helper.rb create mode 100644 src/crypto-donations/crypto-donations.ts create mode 100644 tsconfig.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..b46c417 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,27 @@ +name: Ruby + +on: + push: + branches: + - master + + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + name: Ruby ${{ matrix.ruby }} + strategy: + matrix: + ruby: + - '2.6.5' + + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run the default task + run: bundle exec rake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a97e381 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +/.bundle/ +/.yardoc +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/tmp/ + +# rspec failure tracking +.rspec_status +*.gem +node_modules/ diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..34c5164 --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--format documentation +--color +--require spec_helper diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..e3462a7 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,13 @@ +AllCops: + TargetRubyVersion: 2.6 + +Style/StringLiterals: + Enabled: true + EnforcedStyle: double_quotes + +Style/StringLiteralsInInterpolation: + Enabled: true + EnforcedStyle: double_quotes + +Layout/LineLength: + Max: 120 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..add520a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +## [Unreleased] + +## [0.1.0] - 2024-06-06 + +- Initial release diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..a7a0c82 --- /dev/null +++ b/Gemfile @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +# Specify your gem's dependencies in jekyll-crypto-donations.gemspec +gemspec + +gem "rake", "~> 13.0" + +gem "rspec", "~> 3.0" + +gem "rubocop", "~> 1.21" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..4b8595a --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,10 @@ +GEM + specs: + +PLATFORMS + x86_64-darwin-21 + +DEPENDENCIES + +BUNDLED WITH + 2.4.6 diff --git a/LICENSE b/LICENSE index 5775736..1e27f31 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -MIT License +The MIT License (MIT) Copyright (c) 2024 Eugene Leontev @@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ac62904 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# Jekyll::CryptoDonations + +## Installation + +Add to your Gemfile: +```ruby +group :jekyll_plugins do + gem 'jekyll-crypto-donations' +end +``` + +## Usage + +Add donation addresses to your `_config.yaml` + +```yaml +crypto_donations: + btc_address: "YOUR_BTC_ADDRESS" + eth_address: "YOUR_ETH_ADDRESS" + usdt_address: "YOUR_USDT_TRC20_ADDRES" +``` + +## Development + +After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. + +To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). + +Use NodeJS version 20 LTS +```bash +$ nvm use 20 --lts +``` +install Typescrypt: `npm install typescript` + +Do not change `assets/js/crypto-donations/crypto-donations.js` manually, make changes with TS at `src/crypto-donations/crypto-donations.ts` and then run: +```bash +$ npx tsc +``` +local gem build: `gem build jekyll-crypto-donations.gemspec` + +## Contributing + +Bug reports and pull requests are welcome on GitHub at https://github.com/madmatvey/jekyll-crypto-donations. + +## License + +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..cca7175 --- /dev/null +++ b/Rakefile @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require "bundler/gem_tasks" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) + +require "rubocop/rake_task" + +RuboCop::RakeTask.new + +task default: %i[spec rubocop] diff --git a/_includes/crypto_donations.html b/_includes/crypto_donations.html new file mode 100644 index 0000000..5defa9d --- /dev/null +++ b/_includes/crypto_donations.html @@ -0,0 +1,18 @@ + +
+

Support us with crypto-donations

+

Already :

+ +

Отправьте донат:

+ +
diff --git a/assets/js/crypto-donations/crypto-donations.js b/assets/js/crypto-donations/crypto-donations.js new file mode 100644 index 0000000..c2f54af --- /dev/null +++ b/assets/js/crypto-donations/crypto-donations.js @@ -0,0 +1,52 @@ +// assets/crypto-donations/crypto-donations.ts +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +function fetchCryptoData(url) { + return __awaiter(this, void 0, void 0, function* () { + const response = yield fetch(url); + return response.json(); + }); +} +export function getDonations(currency, address) { + return __awaiter(this, void 0, void 0, function* () { + try { + let response; + switch (currency) { + case 'btc': + const btcApiUrl = `https://api.blockcypher.com/v1/btc/main/addrs/${address}/balance`; + response = yield fetch(btcApiUrl); + if (!response.ok) + throw new Error('blockcypher api response was not ok'); + const btcData = yield response.json(); + return (btcData.total_received / 100000000).toFixed(8); + case 'eth': + const etcApiUrl = `https://api.ethplorer.io/getAddressInfo/${address}?apiKey=freekey`; + response = yield fetch(etcApiUrl); + if (!response.ok) + throw new Error('etherscan api response was not ok'); + const ethData = yield response.json(); + return (ethData.ETH.balance).toFixed(18); + case 'usdt': + response = yield fetch(`https://apilist.tronscan.org/api/account?address=${address}`); + if (!response.ok) + throw new Error('tronscan.org API response was not ok'); + const usdtData = yield response.json(); + const usdtToken = usdtData.trc20token_balances.find((token) => token.tokenAbbr === 'USDT'); + return (usdtToken.balance / 1000000).toFixed(2); // Balance USDT + default: + throw new Error('Unsupported currency'); + } + } + catch (error) { + console.error('Error fetching donation data:', error); + return '0.0'; + } + }); +} diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..776e7f1 --- /dev/null +++ b/bin/console @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "bundler/setup" +require "jekyll/crypto/donations" + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +# (If you use this, don't forget to add pry to your Gemfile!) +# require "pry" +# Pry.start + +require "irb" +IRB.start(__FILE__) diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here diff --git a/jekyll-crypto-donations.gemspec b/jekyll-crypto-donations.gemspec new file mode 100644 index 0000000..9d211de --- /dev/null +++ b/jekyll-crypto-donations.gemspec @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require_relative "lib/jekyll-crypto-donations/version" + +Gem::Specification.new do |spec| + spec.name = "jekyll-crypto-donations" + spec.version = Jekyll::CryptoDonations::VERSION + spec.authors = ["madmatvey"] + spec.email = ["potehin@gmail.com"] + + spec.summary = "A Jekyll plugin for crypto donations" + spec.description = "This plugin allows you to collect and display cryptocurrency donations on your Jekyll site." + spec.homepage = "https://github.com/madmatvey/jekyll-crypto-donations" + spec.license = "MIT" + spec.required_ruby_version = ">= 2.6.0" + + spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" + + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://github.com/madmatvey/jekyll-crypto-donations.git" + spec.metadata["changelog_uri"] = "https://github.com/madmatvey/jekyll-crypto-donations/blob/master/CHANGELOG.md" + + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + # all_files = `git ls-files -z`.split("\x0") + spec.files = Dir['lib/**/*.rb'] + Dir['assets/js/**/*.js'] + spec.extra_rdoc_files = %w[README.md LICENSE] + spec.require_paths = ["lib"] + + # Uncomment to register a new dependency of your gem + # spec.add_dependency "example-gem", "~> 1.0" + spec.add_runtime_dependency 'jekyll', '~> 4.3' + + spec.add_development_dependency "bundler", "~> 2.0" + spec.add_development_dependency "rake", "~> 13.0" + + # For more information and examples about making a new gem, check out our + # guide at: https://bundler.io/guides/creating_gem.html +end diff --git a/lib/jekyll-crypto-donations.rb b/lib/jekyll-crypto-donations.rb new file mode 100644 index 0000000..62a44d1 --- /dev/null +++ b/lib/jekyll-crypto-donations.rb @@ -0,0 +1,72 @@ +require "jekyll-crypto-donations/version" + +module Jekyll + module CryptoDonations + class DonationsTag < Liquid::Tag + def initialize(tag_name, text, tokens) + super + @text = text + end + + def render(context) + # Получаем адреса кошельков из конфигурации Jekyll + 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') + xmr_address = site_config.dig('crypto_donations', 'xmr_address') + usdt_address = site_config.dig('crypto_donations', 'usdt_address') + + # HTML и TypeScript код + <<~HTML +
+

Support Us with Crypto Donations

+

#{@text}

+
+

Bitcoin (BTC)

+

#{btc_address}

+

Loading...

+
+
+

Ethereum (ETH)

+

#{eth_address}

+

Loading...

+
+
+

USDT (TRC-20)

+

Address: #{usdt_address}

+

Loading...

+
+
+ + HTML + end + end + end +end + +Liquid::Template.register_tag('crypto_donations', Jekyll::CryptoDonations::DonationsTag) + +Jekyll::Hooks.register :site, :post_write do |site| + source = File.expand_path("../assets/js/crypto-donations/crypto-donations.js", __dir__) + destination = File.join(site.dest, "assets/js/crypto-donations/crypto-donations.js") + FileUtils.mkdir_p(File.dirname(destination)) + FileUtils.cp(source, destination) +end \ No newline at end of file diff --git a/lib/jekyll-crypto-donations/jekyll-crypto-donations.rb b/lib/jekyll-crypto-donations/jekyll-crypto-donations.rb new file mode 100644 index 0000000..bc01345 --- /dev/null +++ b/lib/jekyll-crypto-donations/jekyll-crypto-donations.rb @@ -0,0 +1,20 @@ +require "jekyll" +require "jekyll-crypto-donations/version" + +module Jekyll + module CryptoDonations + class Generator < Jekyll::Generator + safe true + priority :highest + + def generate(site) + site.data['crypto_donations'] = { + 'btc' => 0.0, + 'eth' => 0.0, + 'xmr' => 0.0, + 'usdt' => 0.0 + } + end + end + end +end diff --git a/lib/jekyll-crypto-donations/version.rb b/lib/jekyll-crypto-donations/version.rb new file mode 100644 index 0000000..1b9cdfe --- /dev/null +++ b/lib/jekyll-crypto-donations/version.rb @@ -0,0 +1,5 @@ +module Jekyll + module CryptoDonations + VERSION = "0.1.0" + end +end \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..379e301 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,24 @@ +{ + "name": "jekyll-crypto-donations", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "typescript": "^5.4.5" + } + }, + "node_modules/typescript": { + "version": "5.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", + "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..783918d --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "typescript": "^5.4.5" + } +} diff --git a/sig/jekyll/crypto/donations.rbs b/sig/jekyll/crypto/donations.rbs new file mode 100644 index 0000000..f2e100e --- /dev/null +++ b/sig/jekyll/crypto/donations.rbs @@ -0,0 +1,8 @@ +module Jekyll + module Crypto + module Donations + VERSION: String + # See the writing guide of rbs: https://github.com/ruby/rbs#guides + end + end +end diff --git a/spec/jekyll/crypto/donations_spec.rb b/spec/jekyll/crypto/donations_spec.rb new file mode 100644 index 0000000..4f576b1 --- /dev/null +++ b/spec/jekyll/crypto/donations_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +RSpec.describe Jekyll::Crypto::Donations do + it "has a version number" do + expect(Jekyll::Crypto::Donations::VERSION).not_to be nil + end + + it "does something useful" do + expect(false).to eq(true) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..0d59fb3 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require "jekyll/crypto/donations" + +RSpec.configure do |config| + # Enable flags like --only-failures and --next-failure + config.example_status_persistence_file_path = ".rspec_status" + + # Disable RSpec exposing methods globally on `Module` and `main` + config.disable_monkey_patching! + + config.expect_with :rspec do |c| + c.syntax = :expect + end +end diff --git a/src/crypto-donations/crypto-donations.ts b/src/crypto-donations/crypto-donations.ts new file mode 100644 index 0000000..6e4472a --- /dev/null +++ b/src/crypto-donations/crypto-donations.ts @@ -0,0 +1,41 @@ +// assets/crypto-donations/crypto-donations.ts + +async function fetchCryptoData(url: string): Promise { + const response = await fetch(url); + return response.json(); +} + +export async function getDonations(currency: string, address: string): Promise { + try { + let response; + switch (currency) { + case 'btc': + const btcApiUrl = `https://api.blockcypher.com/v1/btc/main/addrs/${address}/balance` + response = await fetch(btcApiUrl); + if (!response.ok) throw new Error('blockcypher api response was not ok'); + const btcData = await response.json(); + return (btcData.total_received / 100000000).toFixed(8); + + case 'eth': + const etcApiUrl = `https://api.ethplorer.io/getAddressInfo/${address}?apiKey=freekey` + response = await fetch(etcApiUrl); + if (!response.ok) throw new Error('etherscan api response was not ok'); + const ethData = await response.json(); + return (ethData.ETH.balance).toFixed(18); + + case 'usdt': + response = await fetch(`https://apilist.tronscan.org/api/account?address=${address}`); + if (!response.ok) throw new Error('tronscan.org API response was not ok'); + const usdtData = await response.json(); + const usdtToken = usdtData.trc20token_balances.find((token: any) => token.tokenAbbr === 'USDT'); + return (usdtToken.balance / 1000000).toFixed(2); // Balance USDT + + default: + throw new Error('Unsupported currency'); + } + } catch (error) { + console.error('Error fetching donation data:', error); + return '0.0'; + } +} + diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..babc7a3 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "ES6", + "module": "ES6", + "outDir": "./assets/js", + "rootDir": "./src", + "strict": true + }, + "include": ["src/**/*.ts"] +} \ No newline at end of file