Sha256: be415a8f76f9c4cb01eae0c01f7e04b52fb7774fc48cabd62318bc48ae080296

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

module Love
  module Share
    class << self

      def md(by_gemname = false)
        if by_gemname
          render_by 'gem', 'md', Love.gems
        else
          render_by 'author', 'md', Love.authors
        end
      end

      def html(by_gemname = false)
        if by_gemname
          render_by 'gem', 'html', Love.gems
        else
          render_by 'author', 'html', Love.authors
        end
      end

      private

      def render_by(type_name, template_type, collection)
        template = \
          File.
            read(
              Love.root.join "../templates/#{template_type}/by_#{type_name}.#{template_type}.erb"
            )
        member_template = \
          File.
            read(
              Love.root.join "../templates/#{template_type}/_#{type_name}.#{template_type}.erb"
            )

        style_content = 'h1 { color: red; }'
        script_content = 'alert(1)'
        begin_content = File.read(Love.root.join "../hearts/ascii1.txt")
        generated_by_content = "This file was respectfully generated by #{Love.octokit.login}"
        end_content = File.read(Love.root.join "../hearts/surfer.txt")

        content = ''
        collection.each do |member|
          content << ERB.new(member_template).result(binding)
        end
        if template_type == 'html'
          File.open('./public/love.html', 'w+') do |f|
            f.write ERB.new(template).result(binding)
          end
        else
          File.open('./LOVE.md', 'w+') do |f|
            f.write ERB.new(template).result(binding)
          end
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
share_some_love-0.1.4 lib/love/share.rb
share_some_love-0.1.3 lib/love/share.rb
share_some_love-0.1.2 lib/love/share.rb
share_some_love-0.1.1 lib/love/share.rb