-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from bdurand/embed_ui
Allow embedding full UI
- Loading branch information
Showing
8 changed files
with
114 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.1.1 | ||
1.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
module UltraSettings | ||
# This class can render information about all configurations. It is used by the bundled | ||
# web UI, but you can use it to embed the configuration information in your own web pages. | ||
# | ||
# The output will be a simple HTML drop down list that can be used to display an HTML table | ||
# showing each configuration. You can specify the CSS class for the select element and the tables | ||
# by passing the `select_class` and `table_class` option to the `render` method. By default the | ||
# select elewment have the class `ultra-settings-select` and the table will have the class | ||
# `ultra-settings-table`. | ||
# | ||
# @example | ||
# <h1>Application Configuration</h1> | ||
# <%= UltraSettings::ApplicationView.new.render(select_class: 'form-control', table_class: "table table-striped") %> | ||
class ApplicationView | ||
@template = nil | ||
|
||
class << self | ||
def template | ||
@template ||= ERB.new(read_app_file("index.html.erb")) | ||
end | ||
|
||
def javascript | ||
@javascript = read_app_file("application.js") | ||
end | ||
|
||
private | ||
|
||
def read_app_file(path) | ||
File.read(File.join(app_dir, path)) | ||
end | ||
|
||
def app_dir | ||
File.expand_path(File.join("..", "..", "app"), __dir__) | ||
end | ||
end | ||
|
||
def render(select_class: "ultra-settings-select", table_class: "ultra-settings-table") | ||
html = self.class.template.result(binding) | ||
html = html.html_safe if html.respond_to?(:html_safe) | ||
html | ||
end | ||
|
||
def to_s | ||
render | ||
end | ||
|
||
private | ||
|
||
def html_escape(value) | ||
ERB::Util.html_escape(value) | ||
end | ||
|
||
def javascript | ||
self.class.javascript | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../spec_helper" | ||
|
||
describe UltraSettings::ApplicationView do | ||
it "renders the confguration as an HTML application" do | ||
html = UltraSettings::ApplicationView.new.render | ||
expect(html.strip).to match(/<select class="ultra-settings-select" size="1" id="config-selector">.*<\/select>/m) | ||
expect(html.strip).to match(/<table class="ultra-settings-table">.*<\/table>/m) | ||
expect(html.strip).to match(/<script>.*<\/script>/m) | ||
end | ||
|
||
it "can set the select class" do | ||
html = UltraSettings::ApplicationView.new.render(select_class: "form-control") | ||
expect(html.strip).to match(/<select class="form-control" size="1" id="config-selector">.*<\/select>/m) | ||
end | ||
|
||
it "can set the table class" do | ||
html = UltraSettings::ApplicationView.new.render(table_class: "table table-striped") | ||
expect(html.strip).to match(/<table class="table table-striped">.*<\/table>/m) | ||
end | ||
|
||
it "renders valid HTML", env: {TEST_STRING: "<script"} do | ||
html = UltraSettings::ApplicationView.new.render | ||
doc = Nokogiri::HTML(html) | ||
expect(doc.errors).to be_empty | ||
end | ||
end |