source_browser 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fc01ebe8cf52d45b5288d2884f8da766e489036b1c05d7024692bb2f6620dd64
4
+ data.tar.gz: f93945cdd7f4d22e613cd687bbc7244b32a8963a579a5e0df7eddef735344e3b
5
+ SHA512:
6
+ metadata.gz: 6af6190eb5be7c8ca3dab742380b9a1162b117014147c472afdb6c5cfb67ea93ecab6a6b47d25fd65a4c98d650aaf6ab0fbc7be645582d9fbb935ea32c510426
7
+ data.tar.gz: 0ab968a2e340c3de5002cc95a731f0c5bf91a75391c303ff162b21188f5144a1215961b05304586c1d67475c022b7a4cc2a9e66a50dffa3099cd519257866e7b
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Jeff Peterson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # SourceBrowser
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "source_browser"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install source_browser
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,6 @@
1
+ module SourceBrowser
2
+ class ApplicationController < ActionController::Base
3
+ delegate :git, to: SourceBrowser
4
+ helper_method :git
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ module SourceBrowser
2
+ class ObjectsController < ApplicationController
3
+ def show
4
+ @path = params[:id]
5
+ @object = git.object(@path)
6
+ render body: @object.contents
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ require "rouge"
2
+
3
+ module SourceBrowser
4
+ class SourceController < ApplicationController
5
+ def index
6
+ @files = git.ls_files
7
+ end
8
+
9
+ def show
10
+ @path = params[:id]
11
+ @object = git.object(@path)
12
+ @files = git.ls_files
13
+
14
+ @formatter = Rouge::Formatters::HTML.new
15
+ @formatter = Rouge::Formatters::HTMLLineTable.new(@formatter, line_id: "L%i", line_format: "<a href='?line=%i'>%i</a>")
16
+ @lexer = Rouge::Lexer.guess(filename: @path, source: @object.contents)
17
+ @source = @formatter.format(@lexer.lex(@object.contents))
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ module SourceBrowser
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module SourceBrowser
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module SourceBrowser
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: "from@example.com"
4
+ layout "mailer"
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module SourceBrowser
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Source browser</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= yield :head %>
9
+
10
+ <%= stylesheet_link_tag "source_browser/application", media: "all" %>
11
+ </head>
12
+ <body>
13
+
14
+ <%= yield %>
15
+
16
+ </body>
17
+ </html>
@@ -0,0 +1,33 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= @path %></title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= yield :head %>
9
+
10
+ <%= stylesheet_link_tag "source_browser/application", media: "all" %>
11
+ <style>
12
+ .rouge-line-table {
13
+ border-collapse: collapse;
14
+ }
15
+ .code { flex-grow: 1;}
16
+ <%= Rouge::Themes::Molokai.render(scope: '.code')%>
17
+ </style>
18
+ </head>
19
+ <body>
20
+ <main style="display: flex; gap: 1rem">
21
+ <nav style="max-width: 500px; flex-shrink: 0; overflow: auto;">
22
+ <ul>
23
+ <% @files.each do |path, _| %>
24
+ <li>
25
+ <%= link_to_unless_current path, browse_path(":" + path) %>
26
+ </li>
27
+ <% end %>
28
+ </ul>
29
+ </nav>
30
+ <div class="code"><%= yield %></div>
31
+ </main>
32
+ </body>
33
+ </html>
File without changes
@@ -0,0 +1 @@
1
+ <%= raw @source %>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ SourceBrowser::Engine.routes.draw do
2
+ root "source#index"
3
+ get "*id" => "source#show", as: :browse, format: false, defaults: {format: 'html'}
4
+ get "objects/*id" => "objects#show", as: :object, format: false, defaults: {format: 'html'}
5
+ end
@@ -0,0 +1,5 @@
1
+ module SourceBrowser
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace SourceBrowser
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module SourceBrowser
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,10 @@
1
+ require "source_browser/version"
2
+ require "source_browser/engine"
3
+ require "git"
4
+
5
+ module SourceBrowser
6
+ # Your code goes here...
7
+ def self.git
8
+ @git ||= Git.open(Rails.root)
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :source_browser do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: source_browser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Peterson
8
+ - Matt Tognetti
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2024-10-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 8.0.0.beta1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 8.0.0.beta1
28
+ - !ruby/object:Gem::Dependency
29
+ name: git
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 2.3.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 2.3.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: rouge
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 4.4.0
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 4.4.0
56
+ description: SourceBrowser is a Rails engine for browsing source code. It is designed
57
+ to be used in a Rails application that is serving web pages to users.
58
+ email:
59
+ - jeff@concept.love
60
+ - matt@concept.love
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - MIT-LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - app/assets/stylesheets/source_browser/application.css
69
+ - app/controllers/source_browser/application_controller.rb
70
+ - app/controllers/source_browser/objects_controller.rb
71
+ - app/controllers/source_browser/source_controller.rb
72
+ - app/helpers/source_browser/application_helper.rb
73
+ - app/jobs/source_browser/application_job.rb
74
+ - app/mailers/source_browser/application_mailer.rb
75
+ - app/models/source_browser/application_record.rb
76
+ - app/views/layouts/source_browser/application.html.erb
77
+ - app/views/layouts/source_browser/source.html.erb
78
+ - app/views/source_browser/source/index.html.erb
79
+ - app/views/source_browser/source/show.html.erb
80
+ - config/routes.rb
81
+ - lib/source_browser.rb
82
+ - lib/source_browser/engine.rb
83
+ - lib/source_browser/version.rb
84
+ - lib/tasks/source_browser_tasks.rake
85
+ homepage: https://github.com/craft-concept/source_browser
86
+ licenses:
87
+ - MIT
88
+ metadata:
89
+ source_code_uri: https://github.com/craft-concept/source_browser
90
+ changelog_uri: https://github.com/craft-concept/source_browser/CHANGELOG.md
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 3.0.0
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 3.5.21
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Rails plugin for browsing source code
110
+ test_files: []