git_banner 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/config/routes.rb +7 -0
- data/lib/generators/git_banner/install/install_generator.rb +19 -0
- data/lib/git_banner/config.rb +28 -0
- data/lib/git_banner/config_editor.rb +52 -0
- data/lib/git_banner/engine.rb +5 -0
- data/lib/git_banner/injector.rb +40 -0
- data/lib/git_banner/railtie.rb +15 -0
- data/lib/git_banner/version.rb +3 -0
- data/lib/git_banner.rb +6 -0
- metadata +78 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 765119a4535854c9cfbb3051cda107e40dccf61d166465ba6acd2f73a69eaa72
         | 
| 4 | 
            +
              data.tar.gz: 3dfcb34884aedacd87eee53b514c81af4e8405cdac73114468c759bb2b66eda0
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: b7e499fd852f24c0e716e4e830573f35adba97a8fbaccc195d9bca38f48d3968d8dce42db1f3ee728c9770ed8b7c1f4c33283c9ae23bcf6597fc439a7cb2b2a0
         | 
| 7 | 
            +
              data.tar.gz: f310543f4c96732c84950727a077ea17c11fac7542e11b1a031688d0e9b75d3acb4dddfd31b393cddd779557281edad18c4f21143eed2f44edf2124d2602e720
         | 
    
        data/config/routes.rb
    ADDED
    
    
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            require "rails/generators"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module GitBanner
         | 
| 4 | 
            +
              module Generators
         | 
| 5 | 
            +
                class InstallGenerator < Rails::Generators::Base
         | 
| 6 | 
            +
                  desc "Mounts GitBanner engine to /git_banner in your routes.rb"
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def mount_engine
         | 
| 9 | 
            +
                    route_code = "  mount GitBanner::Engine => '/git_banner'\n"
         | 
| 10 | 
            +
                    routes_file = "config/routes.rb"
         | 
| 11 | 
            +
                    content = File.read(routes_file)
         | 
| 12 | 
            +
                    unless content.include?("mount GitBanner::Engine")
         | 
| 13 | 
            +
                      updated = content.sub(/Rails.application.routes.draw do\n/, "\0" + route_code)
         | 
| 14 | 
            +
                      File.write(routes_file, updated)
         | 
| 15 | 
            +
                    end
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module GitBanner
         | 
| 4 | 
            +
              class Config
         | 
| 5 | 
            +
                def self.settings
         | 
| 6 | 
            +
                  if Rails.env.development?
         | 
| 7 | 
            +
                    load_settings
         | 
| 8 | 
            +
                  else
         | 
| 9 | 
            +
                    @settings ||= load_settings
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def self.load_settings
         | 
| 14 | 
            +
                  file = Rails.root.join('config', 'git_banner_settings.json')
         | 
| 15 | 
            +
                  if File.exist?(file)
         | 
| 16 | 
            +
                    JSON.parse(File.read(file), symbolize_names: true)
         | 
| 17 | 
            +
                  else
         | 
| 18 | 
            +
                    {
         | 
| 19 | 
            +
                      background: "#222",
         | 
| 20 | 
            +
                      color: "#ccc",
         | 
| 21 | 
            +
                      font_size: "12px",
         | 
| 22 | 
            +
                      font_family: "monospace",
         | 
| 23 | 
            +
                      show_in: ["development", "staging"]
         | 
| 24 | 
            +
                    }
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
| @@ -0,0 +1,52 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
            require 'rack/utils'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module GitBanner
         | 
| 5 | 
            +
              class ConfigEditor
         | 
| 6 | 
            +
                def self.call(env)
         | 
| 7 | 
            +
                  req = Rack::Request.new(env)
         | 
| 8 | 
            +
                  file_path = Rails.root.join('config', 'git_banner_settings.json')
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  if req.post?
         | 
| 11 | 
            +
                    params = req.POST
         | 
| 12 | 
            +
                    settings = {
         | 
| 13 | 
            +
                      background: params["background"],
         | 
| 14 | 
            +
                      color: params["color"],
         | 
| 15 | 
            +
                      font_size: params["font_size"],
         | 
| 16 | 
            +
                      font_family: params["font_family"],
         | 
| 17 | 
            +
                      show_in: params["show_in"].split(",").map(&:strip)
         | 
| 18 | 
            +
                    }
         | 
| 19 | 
            +
                    File.write(file_path, JSON.pretty_generate(settings))
         | 
| 20 | 
            +
                    return [302, { "Location" => "/git_banner/editor" }, ["Updated"]]
         | 
| 21 | 
            +
                  else
         | 
| 22 | 
            +
                    current = File.exist?(file_path) ? JSON.parse(File.read(file_path)) : {}
         | 
| 23 | 
            +
                    html = <<~HTML
         | 
| 24 | 
            +
                    <html><head><title>GitBanner Settings</title>
         | 
| 25 | 
            +
                    <script>
         | 
| 26 | 
            +
                    function updatePreview() {
         | 
| 27 | 
            +
                      let b = document.getElementById("preview");
         | 
| 28 | 
            +
                      b.style.background = document.getElementsByName("background")[0].value;
         | 
| 29 | 
            +
                      b.style.color = document.getElementsByName("color")[0].value;
         | 
| 30 | 
            +
                      b.style.fontSize = document.getElementsByName("font_size")[0].value;
         | 
| 31 | 
            +
                      b.style.fontFamily = document.getElementsByName("font_family")[0].value;
         | 
| 32 | 
            +
                    }
         | 
| 33 | 
            +
                    window.onload = updatePreview;
         | 
| 34 | 
            +
                    </script></head><body oninput="updatePreview()">
         | 
| 35 | 
            +
                    <h2>Configure GitBanner</h2>
         | 
| 36 | 
            +
                    <form method="POST">
         | 
| 37 | 
            +
                      <label>Background: <input type="color" name="background" value="#{current["background"] || "#222"}"></label><br>
         | 
| 38 | 
            +
                      <label>Color: <input type="color" name="color" value="#{current["color"] || "#ccc"}"></label><br>
         | 
| 39 | 
            +
                      <label>Font size: <input type="text" name="font_size" value="#{current["font_size"] || "12px"}"></label><br>
         | 
| 40 | 
            +
                      <label>Font family: <input type="text" name="font_family" value="#{current["font_family"] || "monospace"}"></label><br>
         | 
| 41 | 
            +
                      <label>Show in (comma): <input type="text" name="show_in" value="#{(current["show_in"] || ["development"]).join(",")}"></label><br>
         | 
| 42 | 
            +
                      <button type="submit">Save</button>
         | 
| 43 | 
            +
                    </form>
         | 
| 44 | 
            +
                    <h3>Preview</h3>
         | 
| 45 | 
            +
                    <div id="preview" style="padding:10px;">Preview version: xxxxx</div>
         | 
| 46 | 
            +
                    </body></html>
         | 
| 47 | 
            +
                    HTML
         | 
| 48 | 
            +
                    return [200, { "Content-Type" => "text/html" }, [html]]
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
            end
         | 
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            module GitBanner
         | 
| 2 | 
            +
              module Injector
         | 
| 3 | 
            +
                extend ActiveSupport::Concern
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                included do
         | 
| 6 | 
            +
                  after_action :inject_git_info
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                private
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def inject_git_info
         | 
| 12 | 
            +
                  return unless html_response?
         | 
| 13 | 
            +
                  return unless response.body&.include?("</body>")
         | 
| 14 | 
            +
                  return unless GitBanner::Config.settings[:show_in].include?(Rails.env)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  info = git_info_html
         | 
| 17 | 
            +
                  response.body = response.body.gsub("</body>", info + "</body>")
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def git_info_html
         | 
| 21 | 
            +
                  commit = {
         | 
| 22 | 
            +
                    hash: `git rev-parse --short HEAD`.strip,
         | 
| 23 | 
            +
                    branch: `git rev-parse --abbrev-ref HEAD`.strip,
         | 
| 24 | 
            +
                    date: `git log -1 --format=%cd --date=iso`.strip,
         | 
| 25 | 
            +
                    message: `git log -1 --pretty=%s`.strip
         | 
| 26 | 
            +
                  }
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  style = GitBanner::Config.settings
         | 
| 29 | 
            +
                  <<~HTML
         | 
| 30 | 
            +
                    <div style="position:fixed; bottom:0; left:0; right:0; background:#{style[:background]}; color:#{style[:color]}; font-size:#{style[:font_size]}; font-family:#{style[:font_family]}; text-align:center; padding:5px; z-index:9999;">
         | 
| 31 | 
            +
                      Version: #{commit[:hash]} — #{commit[:branch]} | #{commit[:date]} | #{commit[:message]}
         | 
| 32 | 
            +
                    </div>
         | 
| 33 | 
            +
                  HTML
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                def html_response?
         | 
| 37 | 
            +
                  request.format.html? && response.content_type.to_s.include?("text/html")
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
            end
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            module GitBanner
         | 
| 2 | 
            +
              class Railtie < ::Rails::Railtie
         | 
| 3 | 
            +
                initializer "git_banner.inject_html" do
         | 
| 4 | 
            +
                  ActiveSupport.on_load(:action_controller) do
         | 
| 5 | 
            +
                    include GitBanner::Injector
         | 
| 6 | 
            +
                  end
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                initializer "git_banner.mount_engine", after: :add_routing_paths do |app|
         | 
| 10 | 
            +
                  app.routes.append do
         | 
| 11 | 
            +
                    mount GitBanner::Engine => "/git_banner"
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
    
        data/lib/git_banner.rb
    ADDED
    
    
    
        metadata
    ADDED
    
    | @@ -0,0 +1,78 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: git_banner
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.3.3
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Govani Gregorio Sanchez Orduña
         | 
| 8 | 
            +
            bindir: bin
         | 
| 9 | 
            +
            cert_chain: []
         | 
| 10 | 
            +
            date: 1980-01-02 00:00:00.000000000 Z
         | 
| 11 | 
            +
            dependencies:
         | 
| 12 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 13 | 
            +
              name: rails
         | 
| 14 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 15 | 
            +
                requirements:
         | 
| 16 | 
            +
                - - ">="
         | 
| 17 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 18 | 
            +
                    version: '6.0'
         | 
| 19 | 
            +
              type: :runtime
         | 
| 20 | 
            +
              prerelease: false
         | 
| 21 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 22 | 
            +
                requirements:
         | 
| 23 | 
            +
                - - ">="
         | 
| 24 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 25 | 
            +
                    version: '6.0'
         | 
| 26 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 27 | 
            +
              name: json
         | 
| 28 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 29 | 
            +
                requirements:
         | 
| 30 | 
            +
                - - ">="
         | 
| 31 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            +
                    version: '0'
         | 
| 33 | 
            +
              type: :runtime
         | 
| 34 | 
            +
              prerelease: false
         | 
| 35 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 36 | 
            +
                requirements:
         | 
| 37 | 
            +
                - - ">="
         | 
| 38 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 39 | 
            +
                    version: '0'
         | 
| 40 | 
            +
            description: Displays Git commit info at the bottom of your Rails application. Easily
         | 
| 41 | 
            +
              configurable with live preview.
         | 
| 42 | 
            +
            email:
         | 
| 43 | 
            +
            - soporte@soyprogramador.liz.mx
         | 
| 44 | 
            +
            executables: []
         | 
| 45 | 
            +
            extensions: []
         | 
| 46 | 
            +
            extra_rdoc_files: []
         | 
| 47 | 
            +
            files:
         | 
| 48 | 
            +
            - config/routes.rb
         | 
| 49 | 
            +
            - lib/generators/git_banner/install/install_generator.rb
         | 
| 50 | 
            +
            - lib/git_banner.rb
         | 
| 51 | 
            +
            - lib/git_banner/config.rb
         | 
| 52 | 
            +
            - lib/git_banner/config_editor.rb
         | 
| 53 | 
            +
            - lib/git_banner/engine.rb
         | 
| 54 | 
            +
            - lib/git_banner/injector.rb
         | 
| 55 | 
            +
            - lib/git_banner/railtie.rb
         | 
| 56 | 
            +
            - lib/git_banner/version.rb
         | 
| 57 | 
            +
            homepage: https://soyprogramador.liz.mx
         | 
| 58 | 
            +
            licenses:
         | 
| 59 | 
            +
            - MIT
         | 
| 60 | 
            +
            metadata: {}
         | 
| 61 | 
            +
            rdoc_options: []
         | 
| 62 | 
            +
            require_paths:
         | 
| 63 | 
            +
            - lib
         | 
| 64 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
              requirements:
         | 
| 66 | 
            +
              - - ">="
         | 
| 67 | 
            +
                - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                  version: '0'
         | 
| 69 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 70 | 
            +
              requirements:
         | 
| 71 | 
            +
              - - ">="
         | 
| 72 | 
            +
                - !ruby/object:Gem::Version
         | 
| 73 | 
            +
                  version: '0'
         | 
| 74 | 
            +
            requirements: []
         | 
| 75 | 
            +
            rubygems_version: 3.6.9
         | 
| 76 | 
            +
            specification_version: 4
         | 
| 77 | 
            +
            summary: Git commit banner for Rails apps
         | 
| 78 | 
            +
            test_files: []
         |