bridgetown-plugin-nano 0.2.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.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +38 -0
  3. data/.rubocop.yml +23 -0
  4. data/CHANGELOG.md +7 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +30 -0
  8. data/Rakefile +5 -0
  9. data/bridgetown-plugin-nano.gemspec +26 -0
  10. data/lib/bridgetown-plugin-nano.rb +4 -0
  11. data/lib/bridgetown-plugin-nano/command.rb +112 -0
  12. data/lib/bridgetown-plugin-nano/command_helpers/database_helpers.rb +42 -0
  13. data/lib/bridgetown-plugin-nano/command_helpers/email_helpers.rb +28 -0
  14. data/lib/bridgetown-plugin-nano/command_helpers/general_helpers.rb +46 -0
  15. data/lib/bridgetown-plugin-nano/command_helpers/jobs_helpers.rb +32 -0
  16. data/lib/bridgetown-plugin-nano/rack_middleware.rb +4 -0
  17. data/lib/bridgetown-plugin-nano/rack_middleware/not_found.rb +23 -0
  18. data/lib/bridgetown-plugin-nano/rack_middleware/static.rb +29 -0
  19. data/lib/bridgetown-plugin-nano/templates/base_classes/application_job.rb +7 -0
  20. data/lib/bridgetown-plugin-nano/templates/base_classes/application_mailer.rb +4 -0
  21. data/lib/bridgetown-plugin-nano/templates/base_classes/application_record.rb +3 -0
  22. data/lib/bridgetown-plugin-nano/templates/bridgetown_root/Rakefile +16 -0
  23. data/lib/bridgetown-plugin-nano/templates/bridgetown_root/config.ru.tt +11 -0
  24. data/lib/bridgetown-plugin-nano/templates/databases/postgresql.yml.tt +85 -0
  25. data/lib/bridgetown-plugin-nano/templates/email/app/views/layouts/mailer.html.erb +14 -0
  26. data/lib/bridgetown-plugin-nano/templates/email/app/views/test_mailer/greetings.html.erb +1 -0
  27. data/lib/bridgetown-plugin-nano/templates/email/config/initializers/email.rb +15 -0
  28. data/lib/bridgetown-plugin-nano/templates/email/test_mailer.rb +6 -0
  29. data/lib/bridgetown-plugin-nano/templates/jobs/test_job.rb +7 -0
  30. data/lib/bridgetown-plugin-nano/templates/new_app/Rakefile +3 -0
  31. data/lib/bridgetown-plugin-nano/templates/new_app/bin/rails +5 -0
  32. data/lib/bridgetown-plugin-nano/templates/new_app/config/application.rb +20 -0
  33. data/lib/bridgetown-plugin-nano/templates/new_app/config/base_classes.rb +2 -0
  34. data/lib/bridgetown-plugin-nano/templates/new_app/config/boot.rb +3 -0
  35. data/lib/bridgetown-plugin-nano/templates/new_app/config/initializers/cors.rb +12 -0
  36. data/lib/bridgetown-plugin-nano/templates/new_app/config/routes.rb.tt +5 -0
  37. data/lib/bridgetown-plugin-nano/templates/new_app/nano_controller.rb +16 -0
  38. data/lib/bridgetown-plugin-nano/version.rb +5 -0
  39. metadata +155 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a6d4e8b58579fa4420e46b3a7971d43e72f4a93dcf78d9cb478077a3d952ea8e
4
+ data.tar.gz: c38c74346a665fde4cd252ff64e1a5ecdd47b47dc85239ffb5d65e6868f504b0
5
+ SHA512:
6
+ metadata.gz: 1c50d7e3edc9424bcd3c9c9dd630801f5349f73b8cbe01823a57e727e4a225da02ff4c2a9b8de20065d73eb6b1ec1e261b60c164381609e4dce6a4e4ed9478ce
7
+ data.tar.gz: 489ec22ee1301cd5fd8abb02717edcdea78d22667d08936481cb4422f8a5c7d45a97c991782b3297d3749cf09aa35480f245f31b055f4ef83a7f4b56dc44fd4b
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ /vendor
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+ *.gem
17
+ Gemfile.lock
18
+ .bundle
19
+ .ruby-version
20
+
21
+ # Node
22
+ node_modules
23
+ .npm
24
+ .node_repl_history
25
+
26
+ # Yarn
27
+ yarn-error.log
28
+ yarn-debug.log*
29
+ .pnp/
30
+ .pnp.js
31
+
32
+ # Yarn Integrity file
33
+ .yarn-integrity
34
+
35
+ spec/dest
36
+ .bridgetown-metadata
37
+ .bridgetown-cache
38
+ .bridgetown-webpack
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ require: rubocop-bridgetown
2
+
3
+ inherit_gem:
4
+ rubocop-bridgetown: .rubocop.yml
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 2.5
8
+ Include:
9
+ - lib/**/*.rb
10
+
11
+ Exclude:
12
+ - .gitignore
13
+ - .rspec
14
+ - .rubocop.yml
15
+
16
+ - Gemfile.lock
17
+ - CHANGELOG.md
18
+ - LICENSE.txt
19
+ - README.md
20
+
21
+ - script/**/*
22
+ - vendor/**/*
23
+ - lib/bridgetown-plugin-nano/templates/**/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # master
2
+
3
+ * Use this file to keep track of plugin updates
4
+
5
+ # 0.1.0 / 2020-05-01
6
+
7
+ * First version
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
5
+
6
+ gem "bridgetown", ENV["BRIDGETOWN_VERSION"] if ENV["BRIDGETOWN_VERSION"]
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020-present
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # bridgetown-plugin-nano
2
+ One-step commands to install and configure a Rails-based Nano API backend for Bridgetown
3
+
4
+ **Coming in Q1 2021!**
5
+
6
+ ## Installation
7
+
8
+ Run this command to add this plugin to your site's Gemfile:
9
+
10
+ ```shell
11
+ $ bundle add bridgetown-plugin-nano -g bridgetown_plugins
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ The plugin will…
17
+
18
+ ## Testing
19
+
20
+ * Run `bundle exec rake` to run the test suite
21
+ * Or run `script/cibuild` to validate with Rubocop and test together.
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it (https://github.com/bridgetownrb/bridgetown-nano-plugin/fork)
26
+ 2. Clone the fork using `git clone` to your local development machine.
27
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 5. Push to the branch (`git push origin my-new-feature`)
30
+ 6. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ task :default => :test
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/bridgetown-plugin-nano/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bridgetown-plugin-nano"
7
+ spec.version = BridgetownPluginNano::VERSION
8
+ spec.author = "Bridgetown Team"
9
+ spec.email = "maintainers@bridgetownrb.com"
10
+ spec.summary = "Sets up a Rails-based Nano API backend for Bridgetown"
11
+ spec.homepage = "https://github.com/bridgetownrb/bridgetown-plugin-nano"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script|spec|features|frontend)/!) }
15
+ spec.test_files = spec.files.grep(%r!^spec/!)
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.required_ruby_version = ">= 2.5.0"
19
+
20
+ spec.add_dependency "bridgetown", ">= 0.15", "< 2.0"
21
+ spec.add_dependency "rack", ">= 2.2"
22
+
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake", "~> 12.0"
25
+ spec.add_development_dependency "rubocop-bridgetown", "~> 0.2"
26
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bridgetown"
4
+ require "bridgetown-plugin-nano/command"
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_all "bridgetown-core/commands/concerns"
4
+
5
+ require "bridgetown-plugin-nano/command_helpers/database_helpers"
6
+ require "bridgetown-plugin-nano/command_helpers/email_helpers"
7
+ require "bridgetown-plugin-nano/command_helpers/general_helpers"
8
+ require "bridgetown-plugin-nano/command_helpers/jobs_helpers"
9
+
10
+ module BridgetownPluginNano
11
+ module Commands
12
+ class Nano < Thor
13
+ include Thor::Actions
14
+ include Bridgetown::Commands::ConfigurationOverridable
15
+ include DatabaseHelpers
16
+ include EmailHelpers
17
+ include GeneralHelpers
18
+ include JobsHelpers
19
+
20
+ attr_reader :folder_name, :database_prefix
21
+
22
+ Bridgetown::Commands::Registrations.register do
23
+ desc "nano <command>", "Install or interact with the Nano backend"
24
+ subcommand "nano", Nano
25
+ end
26
+
27
+ def self.source_root
28
+ File.expand_path("templates", __dir__)
29
+ end
30
+
31
+ desc "new [NAME optional]", "Install a new Nano backend into the destination " \
32
+ 'subfolder (default "backend") of the Bridgetown site'
33
+ def new(folder_name = "backend")
34
+ @folder_name = folder_name
35
+ self.destination_root = File.expand_path(folder_name)
36
+
37
+ say_status :nano, %(Setting up Nano in "#{folder_name}")
38
+ directory "new_app", ".", exclude_pattern: %r!DS_Store$!
39
+
40
+ self.destination_root = File.expand_path(".")
41
+ configure_new_nano_app # GeneralHelpers
42
+ end
43
+
44
+ desc "about", "Prints information about your Rails configuration"
45
+ def about
46
+ determine_folder_name
47
+ system("cd #{folder_name} && bundle exec rails about")
48
+ end
49
+
50
+ desc "database TYPE:PREFIX", 'Configure a database (types: "postgresql") and ' \
51
+ "use prefix in database name"
52
+ def database(type_prefix)
53
+ # NOTE: self.database_prefix is accessed by the YAML template
54
+ dbtype, @database_prefix = type_prefix.split(":")
55
+
56
+ determine_folder_name
57
+
58
+ case dbtype
59
+ when "postgresql"
60
+ setup_postgresql
61
+ else
62
+ raise "The #{dbtype} database type is not supported"
63
+ end
64
+
65
+ finish_database_setup # DatabaseHelpers
66
+ end
67
+
68
+ desc "email", "Configure ActionMailer for sending emails"
69
+ def email
70
+ determine_folder_name
71
+ configure_action_mailer
72
+ end
73
+
74
+ desc "jobs", "Configure ActiveJob for async background tasks"
75
+ def jobs
76
+ determine_folder_name
77
+ configure_active_job
78
+ end
79
+
80
+ desc "exec", "Execute any Rails subcommand"
81
+ def exec(*args)
82
+ determine_folder_name
83
+ system("cd #{folder_name} && bundle exec rails #{args.join(" ")}")
84
+ end
85
+
86
+ desc "console", %(Rails console (short-cut alias: "c"))
87
+ def console
88
+ determine_folder_name
89
+ system("cd #{folder_name} && bundle exec rails console")
90
+ end
91
+
92
+ desc "generate", %(Rails generator (short-cut alias: "g"))
93
+ def generate(*args)
94
+ determine_folder_name
95
+ system("cd #{folder_name} && bundle exec rails generate #{args.join(" ")}")
96
+ end
97
+
98
+ private
99
+
100
+ def determine_folder_name
101
+ rackfile = File.read("config.ru")
102
+ matches = %r!require_relative "\./(.*?)/config/application"!.match(rackfile)
103
+ if matches
104
+ @folder_name = matches[1]
105
+ else
106
+ raise "Nano backend folder could not be determined. Is there an" \
107
+ "appropriate require_relative statement in your config.ru file?"
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownPluginNano
4
+ module Commands
5
+ class Nano < Thor
6
+ module DatabaseHelpers
7
+ def setup_postgresql
8
+ template "databases/postgresql.yml", "#{folder_name}/config/database.yml"
9
+
10
+ create_file "#{folder_name}/db/.keep", ""
11
+
12
+ append_to_file "Gemfile" do
13
+ <<~RUBY
14
+
15
+ if ENV["RAILS_ENV"]
16
+ gem "pg"
17
+ end
18
+ RUBY
19
+ end
20
+ end
21
+
22
+ def finish_database_setup
23
+ self.destination_root = File.expand_path(folder_name)
24
+
25
+ append_to_file(
26
+ "config/base_classes.rb",
27
+ "\n" + File.read("#{self.class.source_root}/base_classes/application_record.rb")
28
+ )
29
+ inject_into_file "config/application.rb",
30
+ "require \"active_record/railtie\"\n",
31
+ after: "require \"action_controller/railtie\"\n"
32
+
33
+ say_status :nano, "Database configuration complete!"
34
+ say_status :nano, "You will need a RAILS_ENV environment variable set,"
35
+ say_status :nano, "then run `bundle install`."
36
+ say_status :nano, "Afterwards, you can now run commands like" \
37
+ " `bridgetown nano exec db:setup` to create your database."
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownPluginNano
4
+ module Commands
5
+ class Nano < Thor
6
+ module EmailHelpers
7
+ def configure_action_mailer
8
+ self.destination_root = File.expand_path(folder_name)
9
+
10
+ say_status :nano, %(Setting up ActionMailer in "#{folder_name}")
11
+ directory "email", ".", exclude_pattern: %r!DS_Store$!
12
+ inject_into_file "config/application.rb",
13
+ "require \"action_mailer/railtie\"\n",
14
+ after: "require \"action_controller/railtie\"\n"
15
+ append_to_file(
16
+ "config/base_classes.rb",
17
+ "\n" + File.read("#{self.class.source_root}/base_classes/application_mailer.rb")
18
+ )
19
+
20
+ say_status :nano, "ActionMailer configuration complete!"
21
+ say_status :nano, "Take a look at #{folder_name}/test_mailer.rb for an example mailer,"
22
+ say_status :nano, "and #{folder_name}/config/initializers/email.rb to set " \
23
+ "up your SMTP connection."
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownPluginNano
4
+ module Commands
5
+ class Nano < Thor
6
+ module GeneralHelpers
7
+ def configure_new_nano_app # rubocop:disable Metrics/MethodLength
8
+ template "bridgetown_root/config.ru", "config.ru"
9
+ copy_file "bridgetown_root/Rakefile", "Rakefile"
10
+
11
+ gsub_file "start.js",
12
+ 'sleep 4; yarn serve --port " + port',
13
+ 'sleep 4; bundle exec rake nano:start -- --port=" + port'
14
+ gsub_file "webpack.config.js",
15
+ %(const path = require("path");\n),
16
+ %(const path = require("path");\nconst webpack = require("webpack");\n)
17
+
18
+ inject_into_file "webpack.config.js", <<-JS, after: "\n plugins: [\n"
19
+ new webpack.DefinePlugin({
20
+ NANO_API_URL: JSON.stringify(process.env.NANO_API_URL || "")
21
+ }),
22
+ JS
23
+
24
+ append_to_file "Gemfile" do
25
+ <<~RUBY
26
+
27
+ # Gems required by the Nano backend:
28
+ gem "dotenv"
29
+ gem "puma"
30
+ gem "rails"
31
+ gem "rack-cors"
32
+ RUBY
33
+ end
34
+ Bridgetown.with_unbundled_env do
35
+ run "bundle install", abort_on_failure: true
36
+ end
37
+
38
+ logger = Bridgetown.logger
39
+ logger.info ""
40
+ logger.info "Success!".green, "🎉 Your Nano backend was" \
41
+ " generated in #{folder_name.cyan}."
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownPluginNano
4
+ module Commands
5
+ class Nano < Thor
6
+ module JobsHelpers
7
+ def configure_active_job
8
+ self.destination_root = File.expand_path(folder_name)
9
+
10
+ say_status :nano, %(Setting up ActiveJob in "#{folder_name}")
11
+ directory "jobs", ".", exclude_pattern: %r!DS_Store$!
12
+ inject_into_file "config/application.rb",
13
+ "require \"active_job/railtie\"\n",
14
+ after: "require \"action_controller/railtie\"\n"
15
+
16
+ inject_into_file "config/application.rb",
17
+ "# config.active_job.queue_adapter = :sidekiq\n",
18
+ after: "Rails.logger = config.logger\n"
19
+ append_to_file(
20
+ "config/base_classes.rb",
21
+ "\n" + File.read("#{self.class.source_root}/base_classes/application_job.rb")
22
+ )
23
+
24
+ say_status :nano, "ActiveJob configuration complete!"
25
+ say_status :nano, "Take a look at #{folder_name}/test_job.rb for an example job,"
26
+ say_status :nano, "and #{folder_name}/config/application.rb to set your " \
27
+ "queue backend (such as Sidekiq)."
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bridgetown-plugin-nano/rack_middleware/not_found"
4
+ require "bridgetown-plugin-nano/rack_middleware/static"
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownPluginNano
4
+ module Middleware
5
+ class NotFound
6
+ def initialize(app, path, content_type = "text/html; charset=utf-8")
7
+ @app = app
8
+ @content = File.read(path)
9
+ @length = @content.bytesize.to_s
10
+ @content_type = content_type
11
+ end
12
+
13
+ def call(env)
14
+ response = @app.call(env)
15
+ if response[0] == 404
16
+ [404, { "Content-Type" => @content_type, "Content-Length" => @length }, [@content]]
17
+ else
18
+ response
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownPluginNano
4
+ module Middleware
5
+ # Based on Rack::TryStatic middleware
6
+ # https://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/try_static.rb
7
+
8
+ class Static
9
+ def initialize(app, options)
10
+ @app = app
11
+ @try = ["", ".html", "index.html", "/index.html", *options[:try]]
12
+ @static = Rack::Static.new(
13
+ ->(_) { [404, {}, []] },
14
+ options
15
+ )
16
+ end
17
+
18
+ def call(env)
19
+ orig_path = env["PATH_INFO"]
20
+ found = nil
21
+ @try.each do |path|
22
+ resp = @static.call(env.merge!({ "PATH_INFO" => orig_path + path }))
23
+ break if !(403..405).cover?(resp[0]) && (found = resp)
24
+ end
25
+ found || @app.call(env.merge!("PATH_INFO" => orig_path))
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ # Automatically retry jobs that encountered a deadlock
3
+ # retry_on ActiveRecord::Deadlocked
4
+
5
+ # Most jobs are safe to ignore if the underlying records are no longer available
6
+ # discard_on ActiveJob::DeserializationError
7
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: "from@example.com"
3
+ layout "mailer"
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,16 @@
1
+ require "rake"
2
+
3
+ namespace :nano do
4
+ desc "Boot up both the Bridgetown watcher and Puma/Rack"
5
+ task :start do
6
+ args = ARGV[1..].reject {|arg| arg == "--" }
7
+
8
+ trap("SIGINT") do
9
+ puts "- Stopping Bridgetown & Puma"
10
+ end
11
+
12
+ Process.spawn("bundle exec bridgetown build -w")
13
+ Process.spawn("bundle exec puma #{args.join(' ')}")
14
+ Process.waitall
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ require "dotenv/load"
2
+ require "bridgetown-plugin-nano/rack_middleware"
3
+ require_relative "./<%= folder_name %>/config/application"
4
+
5
+ if Dir.exist?("output")
6
+ # Only use static middleware if the output folder exists:
7
+ use BridgetownPluginNano::Middleware::Static, root: "output", urls: %w[/]
8
+ use BridgetownPluginNano::Middleware::NotFound, "output/404.html"
9
+ end
10
+
11
+ run NanoAPI
@@ -0,0 +1,85 @@
1
+ # PostgreSQL. Versions 9.3 and up are supported.
2
+ #
3
+ # Install the pg driver:
4
+ # gem install pg
5
+ # On macOS with Homebrew:
6
+ # gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7
+ # On macOS with MacPorts:
8
+ # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
9
+ # On Windows:
10
+ # gem install pg
11
+ # Choose the win32 build.
12
+ # Install PostgreSQL and put its /bin directory on your path.
13
+ #
14
+ # Configure Using Gemfile
15
+ # gem 'pg'
16
+ #
17
+ default: &default
18
+ adapter: postgresql
19
+ encoding: unicode
20
+ # For details on connection pooling, see Rails configuration guide
21
+ # https://guides.rubyonrails.org/configuring.html#database-pooling
22
+ pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
23
+
24
+ development:
25
+ <<: *default
26
+ database: <%= database_prefix %>_development
27
+
28
+ # The specified database role being used to connect to postgres.
29
+ # To create additional roles in postgres see `$ createuser --help`.
30
+ # When left blank, postgres will use the default role. This is
31
+ # the same name as the operating system user that initialized the database.
32
+ #username: <%= database_prefix %>
33
+
34
+ # The password associated with the postgres role (username).
35
+ #password:
36
+
37
+ # Connect on a TCP socket. Omitted by default since the client uses a
38
+ # domain socket that doesn't need configuration. Windows does not have
39
+ # domain sockets, so uncomment these lines.
40
+ #host: localhost
41
+
42
+ # The TCP port the server listens on. Defaults to 5432.
43
+ # If your server runs on a different port number, change accordingly.
44
+ #port: 5432
45
+
46
+ # Schema search path. The server defaults to $user,public
47
+ #schema_search_path: myapp,sharedapp,public
48
+
49
+ # Minimum log levels, in increasing order:
50
+ # debug5, debug4, debug3, debug2, debug1,
51
+ # log, notice, warning, error, fatal, and panic
52
+ # Defaults to warning.
53
+ #min_messages: notice
54
+
55
+ # Warning: The database defined as "test" will be erased and
56
+ # re-generated from your development database when you run "rake".
57
+ # Do not set this db to the same as development or production.
58
+ test:
59
+ <<: *default
60
+ database: <%= database_prefix %>_test
61
+
62
+ # As with config/credentials.yml, you never want to store sensitive information,
63
+ # like your database password, in your source code. If your source code is
64
+ # ever seen by anyone, they now have access to your database.
65
+ #
66
+ # Instead, provide the password as a unix environment variable when you boot
67
+ # the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
68
+ # for a full rundown on how to provide these environment variables in a
69
+ # production deployment.
70
+ #
71
+ # On Heroku and other platform providers, you may have a full connection URL
72
+ # available as an environment variable. For example:
73
+ #
74
+ # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
75
+ #
76
+ # You can use this database configuration with:
77
+ #
78
+ # production:
79
+ # url: <%%= ENV['DATABASE_URL'] %>
80
+ #
81
+ production:
82
+ <<: *default
83
+ database: <%= database_prefix %>_production
84
+ username: <%= database_prefix %>
85
+ password: <%%= ENV['<%= database_prefix.upcase %>_DATABASE_PASSWORD'] %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <h1>Email Template</h1>
12
+ <%= yield %>
13
+ </body>
14
+ </html>
@@ -0,0 +1 @@
1
+ <p>Howdy! Nice to meet you <%= @name %> 😎</p>
@@ -0,0 +1,15 @@
1
+ # This is only one example of configuring ActionMailer, in this case SendGrid.
2
+ # For more information, read: https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration
3
+
4
+ Rails.application.configure do
5
+ config.action_mailer.delivery_method = :smtp
6
+ config.action_mailer.smtp_settings = {
7
+ address: "smtp.sendgrid.net",
8
+ port: 587,
9
+ domain: ENV["SENDGRID_DOMAIN"],
10
+ user_name: ENV["SENDGRID_USERNAME"],
11
+ password: ENV["SENDGRID_KEY"],
12
+ authentication: "plain",
13
+ enable_starttls_auto: true
14
+ }
15
+ end
@@ -0,0 +1,6 @@
1
+ class TestMailer < ApplicationMailer
2
+ def greetings
3
+ @name = params[:name]
4
+ mail(to: params[:recipient], subject: "Welcome to My Awesome Site")
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ class TestJob < ApplicationJob
2
+ queue_as :default
3
+
4
+ def perform(*args)
5
+ Rails.logger.info "TestJob successfully run! Args: #{args}"
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ require_relative "config/application"
2
+
3
+ Rails.application.load_tasks
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ APP_PATH = File.expand_path('../config/application', __dir__)
4
+ require_relative '../config/boot'
5
+ require 'rails/commands'
@@ -0,0 +1,20 @@
1
+ require "action_controller/railtie"
2
+
3
+ class NanoAPI < Rails::Application
4
+ config.root = File.dirname(__dir__) # set the root to `backend`
5
+ config.autoloader = :zeitwerk
6
+ if Rails.env.production?
7
+ config.eager_load = true
8
+ config.cache_classes = true
9
+ else
10
+ config.eager_load = false
11
+ end
12
+ config.autoload_paths << File.dirname(__dir__) # autoload right from `backend`
13
+ config.api_only = true # removes middleware we don't need
14
+ config.logger = ActiveSupport::Logger.new($stdout)
15
+ Rails.logger = config.logger
16
+ config.filter_parameters += [:password]
17
+ config.secret_key_base = ENV["SECRET_KEY_BASE"] # Rails won't boot w/o a secret token for session, cookies, etc.
18
+ end
19
+
20
+ NanoAPI.initialize!
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,3 @@
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __dir__)
2
+
3
+ require 'bundler/setup' # Set up gems listed in the Gemfile.
@@ -0,0 +1,12 @@
1
+ require "rack/cors"
2
+
3
+ Rails.application.config.middleware.insert_before 0, Rack::Cors, logger: (-> { Rails.logger }) do
4
+ allow do
5
+ origins "*"
6
+
7
+ resource "*",
8
+ headers: :any,
9
+ methods: [:get, :post, :delete, :put, :patch, :options, :head],
10
+ max_age: 0
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ scope "/<%= folder_name %>" do
3
+ resources :nano
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ class NanoController < ApplicationController
2
+ def index
3
+ render json: {
4
+ status: "index route",
5
+ hello: "Howdy! I'm Nano, your friendly neighborhood Ruby on Rails backend. :)",
6
+ current_time: Time.now
7
+ }
8
+ end
9
+
10
+ def show
11
+ render json: {
12
+ status: "show route",
13
+ id: params[:id]
14
+ }
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownPluginNano
4
+ VERSION = "0.2.0"
5
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bridgetown-plugin-nano
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Bridgetown Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bridgetown
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.15'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0.15'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rack
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '2.2'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '2.2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '12.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '12.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rubocop-bridgetown
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0.2'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.2'
89
+ description:
90
+ email: maintainers@bridgetownrb.com
91
+ executables: []
92
+ extensions: []
93
+ extra_rdoc_files: []
94
+ files:
95
+ - ".gitignore"
96
+ - ".rubocop.yml"
97
+ - CHANGELOG.md
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - bridgetown-plugin-nano.gemspec
103
+ - lib/bridgetown-plugin-nano.rb
104
+ - lib/bridgetown-plugin-nano/command.rb
105
+ - lib/bridgetown-plugin-nano/command_helpers/database_helpers.rb
106
+ - lib/bridgetown-plugin-nano/command_helpers/email_helpers.rb
107
+ - lib/bridgetown-plugin-nano/command_helpers/general_helpers.rb
108
+ - lib/bridgetown-plugin-nano/command_helpers/jobs_helpers.rb
109
+ - lib/bridgetown-plugin-nano/rack_middleware.rb
110
+ - lib/bridgetown-plugin-nano/rack_middleware/not_found.rb
111
+ - lib/bridgetown-plugin-nano/rack_middleware/static.rb
112
+ - lib/bridgetown-plugin-nano/templates/base_classes/application_job.rb
113
+ - lib/bridgetown-plugin-nano/templates/base_classes/application_mailer.rb
114
+ - lib/bridgetown-plugin-nano/templates/base_classes/application_record.rb
115
+ - lib/bridgetown-plugin-nano/templates/bridgetown_root/Rakefile
116
+ - lib/bridgetown-plugin-nano/templates/bridgetown_root/config.ru.tt
117
+ - lib/bridgetown-plugin-nano/templates/databases/postgresql.yml.tt
118
+ - lib/bridgetown-plugin-nano/templates/email/app/views/layouts/mailer.html.erb
119
+ - lib/bridgetown-plugin-nano/templates/email/app/views/test_mailer/greetings.html.erb
120
+ - lib/bridgetown-plugin-nano/templates/email/config/initializers/email.rb
121
+ - lib/bridgetown-plugin-nano/templates/email/test_mailer.rb
122
+ - lib/bridgetown-plugin-nano/templates/jobs/test_job.rb
123
+ - lib/bridgetown-plugin-nano/templates/new_app/Rakefile
124
+ - lib/bridgetown-plugin-nano/templates/new_app/bin/rails
125
+ - lib/bridgetown-plugin-nano/templates/new_app/config/application.rb
126
+ - lib/bridgetown-plugin-nano/templates/new_app/config/base_classes.rb
127
+ - lib/bridgetown-plugin-nano/templates/new_app/config/boot.rb
128
+ - lib/bridgetown-plugin-nano/templates/new_app/config/initializers/cors.rb
129
+ - lib/bridgetown-plugin-nano/templates/new_app/config/routes.rb.tt
130
+ - lib/bridgetown-plugin-nano/templates/new_app/nano_controller.rb
131
+ - lib/bridgetown-plugin-nano/version.rb
132
+ homepage: https://github.com/bridgetownrb/bridgetown-plugin-nano
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 2.5.0
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubygems_version: 3.1.4
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Sets up a Rails-based Nano API backend for Bridgetown
155
+ test_files: []