forked from jnunemaker/flipper-ui
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Getting things started by rendering a flippin image.
- Loading branch information
1 parent
af1ab44
commit d253359
Showing
17 changed files
with
280 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in flipper-ui.gemspec | ||
gemspec | ||
|
||
gem 'rake' | ||
|
||
group(:guard) do | ||
gem 'guard' | ||
gem 'guard-rspec' | ||
gem 'guard-bundler' | ||
gem 'terminal-notifier-guard' | ||
gem 'rb-fsevent' | ||
end | ||
|
||
group(:test) do | ||
gem 'rspec' | ||
gem 'rack-test' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# A sample Guardfile | ||
# More info at https://github.com/guard/guard#readme | ||
|
||
guard 'bundler' do | ||
watch('Gemfile') | ||
watch(/^.+\.gemspec/) | ||
end | ||
|
||
guard 'rspec' do | ||
watch(%r{^spec/.+_spec\.rb$}) { "spec" } | ||
watch(%r{^lib/(.+)\.rb$}) { "spec" } | ||
watch('spec/helper.rb') { "spec" } | ||
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,19 @@ | ||
# Nothing to see here... move along. | ||
# Sets up load path for examples and requires some stuff | ||
require 'pp' | ||
require 'pathname' | ||
|
||
root_path = Pathname(__FILE__).dirname.join('..').expand_path | ||
lib_path = root_path.join('lib') | ||
$:.unshift(lib_path) | ||
|
||
require 'flipper-ui' | ||
require 'flipper/adapters/memory' | ||
|
||
adapter = Flipper::Adapters::Memory.new({}) | ||
flipper = Flipper.new(adapter) | ||
|
||
use Flipper::UI::Middleware, flipper | ||
run lambda { |env| | ||
[200, {'Content-Type' => 'text/html'}, ['Go here for <a href="/flipper">Flipper!</a>']] | ||
} |
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,17 +1,20 @@ | ||
# -*- encoding: utf-8 -*- | ||
require File.expand_path('../lib/flipper-ui/version', __FILE__) | ||
require File.expand_path('../lib/flipper/ui/version', __FILE__) | ||
|
||
Gem::Specification.new do |gem| | ||
gem.authors = ["John Nunemaker"] | ||
gem.email = ["nunemaker@gmail.com"] | ||
gem.description = %q{TODO: Write a gem description} | ||
gem.summary = %q{TODO: Write a gem summary} | ||
gem.homepage = "" | ||
gem.description = %q{UI for the Flipper gem} | ||
gem.summary = %q{UI for the Flipper gem} | ||
gem.homepage = "https://github.com/jnunemaker/flipper-ui" | ||
|
||
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
gem.files = `git ls-files`.split("\n") | ||
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
gem.name = "flipper-ui" | ||
gem.require_paths = ["lib"] | ||
gem.version = Flipper::Ui::VERSION | ||
gem.version = Flipper::UI::VERSION | ||
|
||
gem.add_dependency 'rack' | ||
gem.add_dependency 'flipper' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1 @@ | ||
require "flipper-ui/version" | ||
|
||
module Flipper | ||
module Ui | ||
# Your code goes here... | ||
end | ||
end | ||
require 'flipper/ui' |
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
require 'flipper' | ||
require 'flipper/ui/middleware' | ||
|
||
module Flipper | ||
module UI | ||
def self.root | ||
@root ||= Pathname(__FILE__).dirname.expand_path.join('ui') | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
require 'pathname' | ||
require 'erb' | ||
require 'rack' | ||
|
||
module Flipper | ||
module UI | ||
class Middleware | ||
def initialize(app, flipper) | ||
@app = app | ||
@flipper = flipper | ||
end | ||
|
||
class Action | ||
def self.views_path | ||
Flipper::UI.root.join('views') | ||
end | ||
|
||
def self.public_path | ||
Flipper::UI.root.join('public') | ||
end | ||
|
||
attr_reader :request | ||
|
||
def initialize(request) | ||
@request = request | ||
@code = 200 | ||
@headers = {'Content-Type' => 'text/html'} | ||
end | ||
|
||
def render(name) | ||
body = render_with_layout do | ||
render_without_layout name | ||
end | ||
|
||
Rack::Response.new(body) | ||
end | ||
|
||
def render_with_layout(&block) | ||
render_template :layout, &block | ||
end | ||
|
||
def render_without_layout(name) | ||
render_template name | ||
end | ||
|
||
def render_template(name) | ||
path = self.class.views_path.join("#{name}.erb") | ||
contents = path.read | ||
compiled = ERB.new(contents) | ||
compiled.result Proc.new {}.binding | ||
end | ||
end | ||
|
||
class Index < Action | ||
def get | ||
render :index | ||
end | ||
end | ||
|
||
class File < Action | ||
def get | ||
Rack::File.new(self.class.public_path).call(request.env) | ||
end | ||
end | ||
|
||
class Route | ||
def self.detect(request) | ||
return unless request.path_info =~ /^\/flipper/ | ||
|
||
case request.path_info | ||
when /\/flipper\/?$/ | ||
Index.new(request) | ||
when /\/flipper\/images\/(.*)/ | ||
File.new(request) | ||
when /\/flipper\/css\/(.*)/ | ||
File.new(request) | ||
end | ||
end | ||
end | ||
|
||
def call(env) | ||
request = Rack::Request.new(env) | ||
|
||
if action = Route.detect(request) | ||
case request.request_method.downcase | ||
when 'get' | ||
action.get | ||
else | ||
raise "#{request.request_method} not supported at this time" | ||
end | ||
else | ||
@app.call(env) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#header h1 a { | ||
display:block; | ||
width:75px; | ||
height:42px; | ||
text-indent: -9999px; | ||
background:url(/flipper/images/logo.png) 0 0 no-repeat; | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,5 @@ | ||
module Flipper | ||
module UI | ||
VERSION = "0.1.0" | ||
end | ||
end |
Empty file.
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,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Flipper</title> | ||
<link rel="stylesheet" type="text/css" href="/flipper/css/application.css"> | ||
</head> | ||
<body> | ||
<div id="header"> | ||
<h1><a href="/">Flipper</a></h1> | ||
</div> | ||
|
||
<div id="content"> | ||
<%= yield %> | ||
</div> | ||
</body> | ||
</html> |
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 @@ | ||
# Logfile created on 2012-09-07 15:05:48 -0400 by logger.rb/31641 |
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,61 @@ | ||
require 'helper' | ||
require 'rack/test' | ||
require 'flipper' | ||
require 'flipper/adapters/memory' | ||
|
||
describe Flipper::UI::Middleware do | ||
include Rack::Test::Methods | ||
|
||
let(:source) { {} } | ||
let(:adapter) { Flipper::Adapters::Memory.new(source) } | ||
let(:flipper) { Flipper.new(adapter) } | ||
|
||
def app | ||
@app ||= begin | ||
middleware = described_class | ||
instance = flipper | ||
|
||
Rack::Builder.new do | ||
use middleware, instance | ||
|
||
map "/" do | ||
run lambda {|env| [404, {}, []] } | ||
end | ||
end.to_app | ||
end | ||
end | ||
|
||
describe "GET /flipper" do | ||
before do | ||
get '/flipper' | ||
end | ||
|
||
it "responds with 200" do | ||
last_response.status.should be(200) | ||
end | ||
|
||
it "renders view" do | ||
last_response.body.should match(/Flipper/) | ||
end | ||
end | ||
|
||
describe "GET /flipper/images/logo.png" do | ||
before do | ||
get '/flipper/images/logo.png' | ||
end | ||
|
||
it "responds with 200" do | ||
last_response.status.should be(200) | ||
end | ||
end | ||
|
||
describe "GET /flipper/css/application.css" do | ||
before do | ||
get '/flipper/css/application.css' | ||
end | ||
|
||
it "responds with 200" do | ||
last_response.status.should be(200) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
$:.unshift(File.expand_path('../../lib', __FILE__)) | ||
|
||
require 'pathname' | ||
require 'logger' | ||
|
||
root_path = Pathname(__FILE__).dirname.join('..').expand_path | ||
lib_path = root_path.join('lib') | ||
log_path = root_path.join('log') | ||
log_path.mkpath | ||
|
||
require 'rubygems' | ||
require 'bundler' | ||
|
||
Bundler.require(:default, :test) | ||
|
||
require 'flipper-ui' | ||
|
||
Logger.new(log_path.join('test.log')) | ||
|
||
RSpec.configure do |config| | ||
config.filter_run :focused => true | ||
config.alias_example_to :fit, :focused => true | ||
config.alias_example_to :xit, :pending => true | ||
config.run_all_when_everything_filtered = true | ||
end |