Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for hosting at sub URL. #67

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class WelcomeController < ApplicationController
def index
if Workshopper::Cache.workshops.keys.length == 1
id = Workshopper::Cache.workshops.keys.first
return redirect_to "/workshop/#{id}/"
return redirect_to controller: 'welcome', action: 'workshop', workshop: id
end

@workshops = Workshopper::Cache.workshops.keys.map do |id|
Expand All @@ -20,7 +20,7 @@ def index
def workshop
@workshop = Workshopper::Cache.workshops[params[:workshop]]
lab = @workshop.active_labs.first
redirect_to "/workshop/#{params[:workshop]}/lab/#{lab}"
redirect_to controller: 'welcome', action: 'lab', workshop: params[:workshop], lab: lab
end

def lab
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<span class="navbar-toggler-icon"></span>
</button>
<% if @workshop %>
<a class="navbar-brand mb-0 h1" href="/workshop/<%= @workshop.id %>" id="workshopName"><%= @workshop.name %></a>
<a class="navbar-brand mb-0 h1" href="<%= url_for(controller: 'welcome', action: 'workshop', workshop: @workshop.id) %>" id="workshopName"><%= @workshop.name %></a>
<% if @lab %>
<span class="navbar-text" style="margin-right: 1rem;">|</span>
<span class="navbar-text"><%= @lab.name %></span>
Expand Down
4 changes: 2 additions & 2 deletions app/views/welcome/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ul>
<% @workshops.each do |workshop| %>
<li><a href="/workshop/<%= workshop[:id] %>"><%= workshop[:name] %></a></li>
<li><a href="<%= url_for(controller: 'welcome', action: 'workshop', workshop: workshop[:id]) %>"><%= workshop[:name] %></a></li>
<% end %>
</ul>
</ul>
10 changes: 5 additions & 5 deletions app/views/welcome/lab.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
<span><%= i += 1 %>. <%= @workshop.lab(id).name %></span>
</li>
<% elsif @completed.include?(@workshop.lab(id).id) %>
<a href="/workshop/<%= @workshop.id %>/lab/<%= @workshop.lab(id).id %>" class="list-group-item list-group-item-action list-group-item-success">
<a href="<%= url_for(controller: 'welcome', action: 'lab', workshop: @workshop.id, lab: @workshop.lab(id).id) %>" class="list-group-item list-group-item-action list-group-item-success">
<%= i += 1 %>. <%= @workshop.lab(id).name %>
</a>
<% else %>
<a href="/workshop/<%= @workshop.id %>/lab/<%= @workshop.lab(id).id %>" class="list-group-item list-group-item-action">
<a href="<%= url_for(controller: 'welcome', action: 'lab', workshop: @workshop.id, lab: @workshop.lab(id).id) %>" class="list-group-item list-group-item-action">
<%= i += 1 %>. <%= @workshop.lab(id).name %>
</a>
<% end %>
<% end %>
<a href="/workshop/<%= @workshop.id %>/complete" class="list-group-item list-group-item-action list-group-item-warning">
<a href="<%= url_for(controller: 'welcome', action: 'complete', workshop: @workshop.id) %>" class="list-group-item list-group-item-action list-group-item-warning">
<i class="fa fa-print"></i> All labs in one page
</a>
<% if ENV['ISSUES_URL'] || @workshop.issues %>
Expand All @@ -53,12 +53,12 @@
</div>
<div class="card-footer">
<% if id > 0 %>
<a href="/workshop/<%= @workshop.id %>/lab/<%= @workshop.lab(@workshop.active_labs[id - 1]).id %>" class="btn btn-primary btn-sm pull-left">
<a href="<%= url_for(controller: 'welcome', action: 'lab', workshop: @workshop.id, lab: @workshop.lab(@workshop.active_labs[id - 1]).id) %>" class="btn btn-primary btn-sm pull-left">
<i class="fa fa-arrow-left"></i> <%= @workshop.lab(@workshop.active_labs[id - 1]).name %>
</a>
<% end %>
<% if id < @workshop.active_labs.length - 1 %>
<a href="/workshop/<%= @workshop.id %>/lab/<%= @workshop.lab(@workshop.active_labs[id + 1]).id %>" class="btn btn-primary btn-sm pull-right">
<a href="<%= url_for(controller: 'welcome', action: 'lab', workshop: @workshop.id, lab: @workshop.lab(@workshop.active_labs[id + 1]).id) %>" class="btn btn-primary btn-sm pull-right">
<%= @workshop.lab(@workshop.active_labs[id + 1]).name %> <i class="fa fa-arrow-right"></i>
</a>
<% end %>
Expand Down
16 changes: 16 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,20 @@

require_relative 'config/environment'

class FixupScriptName
def initialize(app)
@app = app
end

def call(env)
env['SCRIPT_NAME'] = ActionController::Base.config.relative_url_root
env['PATH_INFO'].delete_prefix!(env['SCRIPT_NAME'])
@app.call(env)
end
end

if ActionController::Base.config.relative_url_root
use FixupScriptName
end

run Rails.application
11 changes: 9 additions & 2 deletions lib/workshopper/renderer/adoc.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
require 'asciidoctor'

include Rails.application.routes.url_helpers

module Workshopper
class Renderer
class Adoc

def render(workshop, content)
imagesdir = url_for(controller: 'welcome', action: 'asset',
workshop: workshop, path: 'images', ext: 'ext',
only_path: true)
imagesdir.delete_suffix!('.ext')

content = Asciidoctor::Document.new(content, attributes: {
'icons' => 'font',
'imagesdir' => "/workshop/#{workshop}/asset/images",
'imagesdir' => imagesdir,
'source-highlighter' => 'coderay',
})
content.convert
end

end
end
end
end