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

Added configurable options to the gem #37

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
5 changes: 3 additions & 2 deletions api_taster.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ Gem::Specification.new do |s|

s.add_dependency 'rails', '>= 3.1.0'
s.add_dependency 'jquery-rails'
s.add_dependency 'sass-rails'
s.add_dependency 'bootstrap-sass', '~> 2.1'
s.add_dependency 'sass-rails', '~> 3.2'
s.add_dependency 'bootstrap-sass', '~> 2.2.2.0'

s.add_dependency 'redcarpet'
s.add_dependency 'remotipart', '~> 1.0'

Expand Down
11 changes: 9 additions & 2 deletions app/controllers/api_taster/routes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module ApiTaster
class RoutesController < ApiTaster::ApplicationController
before_filter :map_routes
helper_method :missing_definitions?, :obsolete_definitions?

def index
@routes = Route.grouped_routes
@has_missing_definitions = Route.missing_definitions.present?
@has_obsolete_definitions = Route.obsolete_definitions.present?
end

def show
Expand All @@ -27,5 +26,13 @@ def obsolete_definitions
def map_routes
Route.map_routes
end

def missing_definitions?
Route.missing_definitions.present? && ApiTaster.config.include_missing_definitions
end

def obsolete_definitions?
Route.obsolete_definitions.present? && ApiTaster.config.include_obsolete_definitions
end
end
end
18 changes: 9 additions & 9 deletions app/views/api_taster/routes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
<div id="list-api-div" class="span5">
<div class="div-container">
<ul class="well nav nav-list">
<% if @has_missing_definitions || @has_obsolete_definitions %>
<% if missing_definitions? || obsolete_definitions? %>
<li class="nav-header">Information</li>
<% if @has_missing_definitions %>
<% if missing_definitions? %>
<%= render 'information_warning_li',
:text => 'Missing Definitions Detected',
:path => missing_definitions_routes_path
%>
:path => missing_definitions_routes_path %>
<% end %>
<% if @has_obsolete_definitions %>
<% if obsolete_definitions? %>
<%= render 'information_warning_li',
:text => 'Obsolete Definitions Detected',
:path => obsolete_definitions_routes_path
%>
:path => obsolete_definitions_routes_path %>
<% end %>
<% end %>
<% @routes.each do |controller, routes| %>
Expand All @@ -23,7 +21,9 @@
<li>
<a href="<%= route_path(route[:id]) %>">
<div class="label-api label-api-full">
<span class="label label-important"><%= route[:verb] %></span>
<span class="label label-important">
<%= route[:verb] %>
</span>
</div>
<strong><%= route[:path] %></strong>
</a>
Expand All @@ -36,7 +36,7 @@
<div id="show-api-div" class="span7">
<div class="div-container">
<div class="alert alert-block alert-info">
<h3>Select an API endpoint on the left to get started. :)</h3>
<h3><%= ApiTaster.config.call_to_action %></h3>
</div>
</div>
</div>
Expand Down
9 changes: 7 additions & 2 deletions app/views/layouts/api_taster/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
<div class="navbar-inner">
<div class="container-fluid">
<ul class="nav">
<li><a class="brand" href="<%= root_path %>">API Taster</a></li>
<li>
<%= link_to ApiTaster.config.title, root_path, class: 'brand' %>
</li>
</ul>
<div class="nav-collapse collapse">
<ul class="nav pull-right">
<li>
<a href="/" target="_blank"><%= Rails.application.class.name %> <i class="icon-share-alt icon-white"></i></a>
<%= link_to ApiTaster.config.app_url, target: '_blank' do %>
<%= ApiTaster.config.app_title %>
<i class="icon-share-alt icon-white"></i>
<% end %>
</li>
</ul>
</div>
Expand Down
1 change: 1 addition & 0 deletions lib/api_taster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'bootstrap-sass'
require 'remotipart'
require 'active_support/dependencies'
require 'api_taster/config'
require 'api_taster/engine'
require 'api_taster/route'
require 'api_taster/mapper'
Expand Down
45 changes: 45 additions & 0 deletions lib/api_taster/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'active_support/configurable'

module ApiTaster
# Configures global settings for ApiTaster
# ApiTaster.configure do |config|
# config.title = 'My Application Name'
# end
def self.configure(&block)
yield @config ||= ApiTaster::Configuration.new
end

# Global settings for ApiTaster
def self.config
@config
end

class Configuration
include ActiveSupport::Configurable

config_accessor :title
config_accessor :call_to_action
config_accessor :app_title
config_accessor :app_url
config_accessor :include_missing_definitions
config_accessor :include_obsolete_definitions

def param_name
config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
end

# define param_name writer (copied from AS::Configurable)
writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__
singleton_class.class_eval writer, __FILE__, line
class_eval writer, __FILE__, line
end

configure do |config|
config.title = 'API Taster'
config.call_to_action = 'Select an API endpoint on the left to get started. :)'
config.app_title = 'Application'
config.app_url = '/'
config.include_missing_definitions = true
config.include_obsolete_definitions = true
end
end