scalar_ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 665e34004852e3c7508b7d672ce7222f1de09183a4549bff71f82144975e476c
4
+ data.tar.gz: 60d68fdb4072cc5dff56e25911270ce05828c7231b9f7cc49aa1b8cc66138100
5
+ SHA512:
6
+ metadata.gz: bb139b0a28acb3e42418370b36611a7eb7ea8c885f02c11c3fda2662b5424a71bb1f5be5c117173662c5ba45ae0dcf8b0ae05475964199335eb242323910718e
7
+ data.tar.gz: 0e27fe32e65004da16237aaa7a4300f5a005f61367fe4d8d0fa3028ec9e0d88d7c1d3d9eb438f5b84de8884cfdea0dd5957e5ce773905f2f8356f4edc6126d83
data/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # Scalar API Reference for Ruby
2
+
3
+ This gem simplifies the integration of [Scalar](https://scalar.com), a modern open-source developer experience platform for your APIs into Ruby applications.
4
+
5
+ ## Installation
6
+
7
+ Add the gem to your application's Gemfile by executing in the terminal:
8
+
9
+ ```bash
10
+ bundle add scalar_ruby
11
+ ```
12
+
13
+ ## Getting Started
14
+
15
+ Statistically, you will likely use the gem for the Ruby on Rails application, so here are instructions on how to set up the Scalar for this framework. In the future, we'll add examples for other popular Ruby frameworks.
16
+
17
+ Once you have installed the gem, go to `config/routes.rb` and mount the `Scalar::UI` to your application.
18
+
19
+ ```ruby
20
+ # config/routes.rb
21
+
22
+ Rails.application.routes.draw do
23
+ mount Scalar::UI, at: '/docs'
24
+ ...
25
+ end
26
+ ```
27
+
28
+ Restart the Rails server, and hit `localhost:3000/docs`. You'll see the default view of the Scalar API reference. It uses the `@scalar/galaxy` OpenAPI reference so that you will have something to play with immediately.
29
+
30
+ Then, if you want to use your OpenAPI specification, you need to re-configure the Scalar.
31
+
32
+ First, create an initializer, say `config/initializers/scalar.rb`. Then, set the desired specification as `config.specification` using the `Scalar.setup` method:
33
+
34
+ ```ruby
35
+ # config/initializers/scalar.rb
36
+
37
+ Scalar.setup do |config|
38
+ config.specification = File.read(Rails.root.join('docs/openapi.yml'))
39
+ end
40
+ ```
41
+
42
+ Also, you can pass a URL to the specification:
43
+
44
+ ```ruby
45
+ # config/initializers/scalar.rb
46
+
47
+ Scalar.setup do |config|
48
+ config.specification = "#{ActionMailer::Base.default_url_options[:host]/openapi.json}"
49
+ end
50
+ ```
51
+
52
+ And that's it! More detailed information on other configuration options is in the section below.
53
+
54
+ ## Configuration
55
+
56
+ Once mounted to your application, the library requires no further configuration. You can immediately start playing with the provided API reference example.
57
+
58
+ Having default configurations set may be an excellent way to validate whether the Scalar fits your project. However, most users would love to utilize their specifications and be able to alter settings.
59
+
60
+ The default configuration can be changed using the `Scalar.setup` method in `config/initializers/scalar.rb`.
61
+
62
+ ```ruby
63
+ # config/initializers/scalar.rb
64
+
65
+ Scalar.setup do |config|
66
+ config.page_title = 'My awesome API!'
67
+ end
68
+ ```
69
+
70
+ Below, you’ll find a complete list of configuration settings:
71
+
72
+ Parameter | Description | Default
73
+ -------------------------------------------|---------------------------------------------------------|------------------------
74
+ `config.page_title` | Defines the page title displayed in the browser tab. | API Reference
75
+ `config.library_url` | Allows to set a specific version of Scalar. By default, it uses the latest version of Scalar, so users get the latest updates and bug fixes. | https://cdn.jsdelivr.net/npm/@scalar/api-reference
76
+ `config.scalar_configuration` | Scalar has a rich set of configuration options if you want to change how it works and looks. A complete list of configuration options can be found [here](https://github.com/scalar/scalar/blob/main/documentation/configuration.md). | {}
77
+ `config.specification` | Allows users to pass their OpenAPI specification to Scalar. It can be a URL to specification or a string object in JSON or YAML format. | https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml
78
+
79
+ Example of setting configuration options:
80
+
81
+ ```ruby
82
+ # config/initializers/scalar.rb
83
+
84
+ Scalar.setup do |config|
85
+ config.scalar_configuration = { theme: 'purple' }
86
+ end
87
+ ```
88
+
89
+ ## Development
90
+
91
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
92
+
93
+ Run `bundle exec rake install` to install this gem onto your local machine. 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).
94
+
95
+ ## Contributing
96
+
97
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dmytroshevchuk/scalar_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/dmytroshevchuk/scalar_ruby/blob/master/CODE_OF_CONDUCT.md).
98
+
99
+ ## License
100
+
101
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
102
+
103
+ ## Code of Conduct
104
+
105
+ Everyone interacting in the Scalar::Ruby project’s codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/dmytroshevchuk/scalar_ruby/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'minitest/test_task'
5
+
6
+ Minitest::TestTask.create
7
+
8
+ task default: :test
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'singleton'
5
+
6
+ module Scalar
7
+ class Config
8
+ include Singleton
9
+
10
+ DEFAULT_LIBRARY_URL = 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'
11
+ DEFAULT_PAGE_TITLE = 'API Reference'
12
+ DEFAULT_SCALAR_CONFIGURATION = {}.freeze
13
+ DEFAULT_SPECIFICATION = 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml'
14
+
15
+ attr_accessor :library_url,
16
+ :page_title,
17
+ :scalar_configuration,
18
+ :specification
19
+
20
+ def initialize
21
+ set_defaults!
22
+ end
23
+
24
+ def scalar_configuration_to_json
25
+ JSON.dump(scalar_configuration)
26
+ end
27
+
28
+ def set_defaults!
29
+ @library_url = DEFAULT_LIBRARY_URL
30
+ @page_title = DEFAULT_PAGE_TITLE
31
+ @scalar_configuration = DEFAULT_SCALAR_CONFIGURATION
32
+ @specification = DEFAULT_SPECIFICATION
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title><%= config.page_title %></title>
5
+
6
+ <meta charset="utf-8" />
7
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
8
+ </head>
9
+
10
+ <body>
11
+ <script
12
+ id="api-reference"
13
+ data-configuration=<%= config.scalar_configuration_to_json %>
14
+ >
15
+ <%= config.specification %>
16
+ </script>
17
+
18
+ <script src="<%= config.library_url %>"></script>
19
+ </body>
20
+ </html>
data/lib/scalar/ui.rb ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+ require_relative 'config'
5
+
6
+ module Scalar
7
+ class UI
8
+ def self.call(_env)
9
+ [
10
+ 200,
11
+ { 'Content-Type' => 'text/html; charset=utf-8' },
12
+ [template.result_with_hash(config: Scalar::Config.instance)]
13
+ ]
14
+ end
15
+
16
+ def self.template
17
+ ERB.new(File.read("#{Scalar::LIB_PATH}/scalar/template.erb"))
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Scalar
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'scalar/config'
4
+ require_relative 'scalar/ui'
5
+
6
+ module Scalar
7
+ LIB_PATH = File.expand_path(File.dirname(__FILE__).to_s)
8
+
9
+ module_function
10
+
11
+ def setup
12
+ yield Scalar::Config.instance
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scalar_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmytro Shevchuk
8
+ - Serhii Ponomarov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2024-11-29 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email:
16
+ - dmytro@hey.com
17
+ - sergii.ponomarov@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - README.md
23
+ - Rakefile
24
+ - lib/scalar/config.rb
25
+ - lib/scalar/template.erb
26
+ - lib/scalar/ui.rb
27
+ - lib/scalar/version.rb
28
+ - lib/scalar_ruby.rb
29
+ homepage: https://github.com/dmytroshevchuk/scalar_ruby
30
+ licenses:
31
+ - MIT
32
+ metadata:
33
+ homepage_uri: https://github.com/dmytroshevchuk/scalar_ruby
34
+ rubygems_mfa_required: 'true'
35
+ source_code_uri: https://github.com/dmytroshevchuk/scalar_ruby
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 2.5.5
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.5.22
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: A gem to automate using Scalar with Ruby apps
55
+ test_files: []