Skip to content

Commit

Permalink
Fixes #26411 - Adapt bastion to an engine
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsherrill committed Mar 29, 2019
1 parent cc1e511 commit 5c1a0d0
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Rails:
AllCops:
Exclude:
- db/migrate/20131014135042_katello_tables.rb
- engines/bastion_katello/node_modules/**/*
- engines/*/node_modules/**/*
- engines/bastion_katello/bastion-*/**/*
- engines/bastion_katello/vendor/assets/dev-components/**/*
- engines/bastion_katello/Rakefile
Expand Down
13 changes: 8 additions & 5 deletions engines/bastion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ BASTION_MODULES.push('myModuleName');

### Plugin Development ###

Bastion supplies a common set of testing and development using Grunt. These Grunt based tasks have been wrapped in Rake to make them more familiar to a Rails developer. To setup your development environment, from your plugin's checkout:
Bastion supplies a common set of testing and development using Grunt. To setup your development environment, from your plugin's checkout:

```
rake bastion:setup
sudo npm install -g grunt-cli
npm install
npm install ../bastion/
```

To run your plugin's tests and lint them:

```
rake bastion:ci
grunt ci
```

### Basics of Adding a New Entity ###
Expand Down Expand Up @@ -188,13 +190,14 @@ Open the file, and add the following lines (with empty lines above and below for
To setup a development environment, clone the repository or your fork of the repository. From the git checkout, setup the required development dependencies by running:

```
rake bastion:setup
sudo npm install -g grunt-cli
npm install
```

After making changes, tests and linting can be run via:

```
rake bastion:ci
grunt ci
```

### Dependencies ###
Expand Down
60 changes: 0 additions & 60 deletions engines/bastion/Rakefile

This file was deleted.

6 changes: 1 addition & 5 deletions engines/bastion/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
Foreman::Application.routes.draw do

class BastionPagesConstraint

def matches?(request)
pages.include?(request.params[:bastion_page])
end

private

def pages
pages = Bastion.plugins.collect { |name, plugin| plugin[:pages] }
pages = Bastion.plugins.collect { |_name, plugin| plugin[:pages] }
pages.flatten
end

end

scope :module => :bastion do
get '/:bastion_page/(*path)', :to => "bastion#index", constraints: BastionPagesConstraint.new
get '/bastion/(*path)', :to => "bastion#index_ie"
end

end
7 changes: 3 additions & 4 deletions engines/bastion/lib/bastion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

require File.expand_path('bastion/engine', File.dirname(__FILE__))

#rubocop:disable Style/ClassVars
module Bastion

@@plugins = {};
@@plugins = {}

def self.plugins
@@plugins
Expand All @@ -23,7 +23,7 @@ def self.config
'relativeUrlRoot' => url_root ? url_root + '/' : '/'
}

Bastion.plugins.each do |name, plugin|
Bastion.plugins.each do |_name, plugin|
base_config.merge!(plugin[:config]) if plugin[:config]
end

Expand All @@ -33,5 +33,4 @@ def self.config
def self.localization_path(locale)
"bastion/angular-i18n/angular-locale_#{locale}.js"
end

end
16 changes: 2 additions & 14 deletions engines/bastion/lib/bastion/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module Bastion
class Engine < ::Rails::Engine

isolate_namespace Bastion

initializer 'bastion.assets_dispatcher', :before => :build_middleware_stack do |app|
Expand All @@ -18,13 +17,13 @@ class Engine < ::Rails::Engine
app.config.assets.paths << "#{Bastion::Engine.root}/vendor/assets/stylesheets/bastion"
end

initializer "bastion.configure_assets", :group => :all do |app|
initializer "bastion.configure_assets", :group => :all do |_app|
SETTINGS[:bastion] = {:assets => {}} if SETTINGS[:bastion].nil?
SETTINGS[:bastion][:assets] = {} if SETTINGS[:bastion][:assets].nil?

SETTINGS[:bastion][:assets][:precompile] = [
'bastion/bastion.css',
'bastion/bastion.js',
'bastion/bastion.js'
]

locale_files = Dir.glob("#{Bastion::Engine.root}/vendor/assets/javascripts/#{Bastion.localization_path("*")}")
Expand All @@ -42,16 +41,5 @@ class Engine < ::Rails::Engine
initializer "angular_templates", :group => :all do |app|
app.config.angular_templates.ignore_prefix = %w([bastion]*\/+)
end

initializer 'bastion.register_plugin', :before => :finisher_hook do
Foreman::Plugin.register :bastion do
requires_foreman '>= 1.15'
end
end

rake_tasks do
load "#{Bastion::Engine.root}/Rakefile"
end

end
end
2 changes: 1 addition & 1 deletion engines/bastion/lib/bastion/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Bastion
VERSION = "6.1.22"
VERSION = "6.1.22".freeze
end
14 changes: 14 additions & 0 deletions engines/bastion_katello/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,19 @@ Bastion is a single page AngularJS based web client for the Katello server. This
All URLs are relative to the application root, `/content-hosts` and `/content_views`, for example, are able to be bookmarked, and work with the browser's back button.
The only real difference, as far as the user is concerned, is that the application is much quicker between Bastion "page loads" since only the HTML needed to render the next page is loaded instead of the entire page.

# Running tests:

```
cd ./engines/bastion_katello
sudo npm update -g grunt-cli
npm install
npm install ../bastion/
```

```
grunt ci
```


## Contributing ##
We welcome contributions, please see the Bastion [developer guide](https://github.com/Katello/bastion/blob/master/README.md).
1 change: 0 additions & 1 deletion engines/bastion_katello/lib/bastion_katello.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require File.expand_path("bastion_katello/engine", File.dirname(__FILE__))
require 'bastion'

module BastionKatello
end
5 changes: 4 additions & 1 deletion engines/bastion_katello/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"name": "bastion_katello",
"version": "1.0.0"
"version": "1.0.0",
"dependencies": {
"bastion": "file:../bastion"
}
}
5 changes: 4 additions & 1 deletion katello.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Gem::Specification.new do |gem|

gem.files = Dir["{app,webpack,vendor,lib,db,ca,config,locale}/**/*"] +
['LICENSE.txt', 'README.md', 'package.json']
gem.files += Dir["engines/bastion/{app,vendor,lib,config}/**/*"]
gem.files += Dir["engines/bastion/{README.md}"]
gem.files += Dir["engines/bastion_katello/{app,vendor,lib,config}/**/*"]
gem.files += Dir["engines/bastion_katello/{README.md}"]
gem.files -= ["lib/katello/tasks/annotate_scenarios.rake"]
Expand Down Expand Up @@ -43,7 +45,8 @@ Gem::Specification.new do |gem|

# UI
gem.add_dependency "deface", '>= 1.0.2', '< 2.0.0'
gem.add_dependency "bastion", ">= 6.1.22", "< 7.0.0"
gem.add_dependency "angular-rails-templates", "~> 1.0.2"
gem.add_development_dependency "uglifier"

# Testing
gem.add_development_dependency "factory_bot_rails", "~> 4.5"
Expand Down
1 change: 1 addition & 0 deletions lib/katello.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
lib_foreman = File.expand_path('lib/foreman', Rails.root)
require lib_foreman if Dir.exist?(lib_foreman)

require File.expand_path("../engines/bastion/lib/bastion", File.dirname(__FILE__))
require File.expand_path("../engines/bastion_katello/lib/bastion_katello", File.dirname(__FILE__))
require "monkeys/anemone"

Expand Down
3 changes: 3 additions & 0 deletions lib/katello/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ def find_katello_assets(args = {})
precompile = [
'katello/katello.css',
'katello/containers/container.css',
'bastion/bastion.css',
'bastion/bastion.js',
/bastion\S+.(?:svg|eot|woff|ttf)$/,
'bastion_katello/bastion_katello.css',
'bastion_katello/bastion_katello.js',
/bastion_katello\S+.(?:svg|eot|woff|ttf)$/
Expand Down

0 comments on commit 5c1a0d0

Please sign in to comment.