Sha256: c65d73d7eca8a0a907b592bec7f5e44b1df26c84fb6eb39e6947345c07bc9929
Contents?: true
Size: 1.92 KB
Versions: 1
Compression:
Stored size: 1.92 KB
Contents
# frozen_string_literal: true # Basic integration example - run code to produce html output # # * Requires .env populated with valid Twitter API creds. # $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) require_relative "./support/jekyll_template" require "jekyll-twitter-plugin" require "erb" OUTPUT_FILENAME = "output_test.html" OPTIONS = [ "oembed https://twitter.com/rubygems/status/518821243320287232", "oembed https://twitter.com/rubygems/status/518821243320287232 align='right' width='350'", "https://twitter.com/rubygems/status/518821243320287232", "oembed https://twitter.com/rubygems/status/missing" ].freeze COLOUR_MAP = { red: 31, green: 32, yellow: 33, blue: 34 }.freeze def say_with_colour(text, colour_name) colour_code = COLOUR_MAP.fetch(colour_name) puts "\e[#{colour_code}m#{text}\e[0m" end class TwitterRenderer Context = Struct.new(:registers) Site = Struct.new(:config) def initialize(options) @options = options @jekyll_context = Context.new(site: Site.new({})) end def render ERB.new(template) .result(binding) .gsub!("src=\"//", "src=\"https://") end private attr_reader :options, :jekyll_context def render_twitter_tag(params) say_with_colour "Fetching with params: #{params}", :yellow TwitterJekyll::TwitterTag.new(nil, params, nil).render(jekyll_context) end def template <<~HTML <html> <body> <h1>jekyll-twitter-plugin output tests</h1> <% options.each do |option| %> <h3><%= option %></h3> <%= render_twitter_tag(option) %> <hr> <% end %> </body> </html> HTML end end def main rederer = TwitterRenderer.new(OPTIONS) File.open(OUTPUT_FILENAME, "w") do |f| f.write rederer.render end end if __FILE__ == $PROGRAM_NAME say_with_colour "Running integration tests...", :red main say_with_colour "Created file: #{OUTPUT_FILENAME}", :green end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jekyll-twitter-plugin-1.4.0 | spec/integration_tests.rb |