From 0da3f93e4d41abbc123ca7321800e852bf0dd92e Mon Sep 17 00:00:00 2001 From: adityashedge Date: Wed, 20 May 2015 21:11:56 +0530 Subject: [PATCH] index page view change(depends on 'rspec_api_documentation' json changes) - added an optional tabular index view. - set 'index_view' configuration to 'tabular' to use alternate view. - default 'index_view' value is 'regular'. - added navbar in 'index_view'. - in 'index_view' links are displayed as Http method + Route url on index page. - eg: 'GET /api/orders' - option to add class to links. - updated test cases fixture json. --- README.md | 1 + lib/public/application.css | 73 ++++++++++++++++++++++++++++++++++++ lib/raddocs/app.rb | 8 +++- lib/raddocs/configuration.rb | 3 ++ lib/raddocs/models.rb | 4 +- lib/views/index.haml | 31 +++++++++++---- lib/views/layout.haml | 19 +++++++--- spec/fixtures/index.json | 8 +++- 8 files changed, 129 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 40047ee..703d17c 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ end * `include_bootstrap` - Boolean to disable including bootstrap if you are using your own css * `external_css` - Array of css files to include, with a full URL to them * `url_prefix` - Optional prefix to insert before URLs generated by Raddocs +* `index_view` - Optional configuration to change the view of index page to tabular format with navbar header by setting value as `tabular`. Requires latest `rspec_api_documentation` gem. Changes display link to Http method + Route Url. eg: `GET /api/orders` ```ruby Raddocs.configure do |config| diff --git a/lib/public/application.css b/lib/public/application.css index 0dc14f8..b87aa32 100644 --- a/lib/public/application.css +++ b/lib/public/application.css @@ -42,3 +42,76 @@ body { font-size: 1.2em; margin-bottom: 15px; } +.navbar { + overflow: visible; + margin-bottom: 20px; + *position: relative; + *z-index: 2; +} +.navbar-inner { + min-height: 40px; + padding-left: 20px; + padding-right: 20px; + background-color: #fafafa; + background-image: -moz-linear-gradient(top, #ffffff, #f2f2f2); + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#f2f2f2)); + background-image: -webkit-linear-gradient(top, #ffffff, #f2f2f2); + background-image: -o-linear-gradient(top, #ffffff, #f2f2f2); + background-image: linear-gradient(to bottom, #ffffff, #f2f2f2); + background-repeat: repeat-x; + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#fff2f2f2', GradientType=0); + border: 1px solid #d4d4d4; + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + border-radius: 4px; + -webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.065); + -moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.065); + box-shadow: 0 1px 4px rgba(0, 0, 0, 0.065); + *zoom: 1; +} +.navbar-inner:before, +.navbar-inner:after { + display: table; + content: ""; + line-height: 0; +} +.navbar-inner:after { + clear: both; +} +.nav-collapse.collapse { + height: auto; + overflow: visible; +} +.navbar .brand { + float: left; + display: block; + padding: 10px 20px 10px; + margin-left: -20px; + font-size: 20px; + font-weight: 200; + color: #777777; + text-shadow: 0 1px 0 #ffffff; +} +.navbar .brand:hover, +.navbar .brand:focus { + text-decoration: none; +} +.navbar-fixed-top, +.navbar-fixed-bottom { + position: fixed; + right: 0; + left: 0; + z-index: 1030; + margin-bottom: 0; +} +.navbar .container { + width: auto; + padding: 0; + margin: 0; +} +.example_link{ + width: 35%; +} +.example_description{ + width: 65%; +} diff --git a/lib/raddocs/app.rb b/lib/raddocs/app.rb index c7a633d..ab35443 100644 --- a/lib/raddocs/app.rb +++ b/lib/raddocs/app.rb @@ -46,8 +46,8 @@ class App < Sinatra::Base end helpers do - def link_to(name, link) - %{#{name}} + def link_to(name, link, options={}) + %{#{name}} end def url_location @@ -87,6 +87,10 @@ def css_files def docs_dir Raddocs.configuration.docs_dir end + + def index_view + Raddocs.configuration.index_view + end end end end diff --git a/lib/raddocs/configuration.rb b/lib/raddocs/configuration.rb index a5dd5c7..683fc0e 100644 --- a/lib/raddocs/configuration.rb +++ b/lib/raddocs/configuration.rb @@ -49,6 +49,9 @@ def self.add_setting(name, opts = {}) # @return [String] defaults to nil add_setting :url_prefix, :default => nil + # @!attribute index_view + # @regular [String] defaults to "regular" + add_setting :index_view, :default => 'regular' private def settings diff --git a/lib/raddocs/models.rb b/lib/raddocs/models.rb index 6ef76b8..b9e9275 100644 --- a/lib/raddocs/models.rb +++ b/lib/raddocs/models.rb @@ -27,11 +27,13 @@ def examples # # Has an extra link attribute that is required only on this page. class IndexExample - attr_reader :description, :link + attr_reader :description, :link, :route_url, :http_method def initialize(attributes) @description = attributes.fetch("description") @link = attributes.fetch("link") + @route_url = attributes.fetch("route") + @http_method = attributes.fetch("method") end # Link to example page is the same name as the file minus ".json" diff --git a/lib/views/index.haml b/lib/views/index.haml index 0c03c60..4ed18d2 100644 --- a/lib/views/index.haml +++ b/lib/views/index.haml @@ -1,9 +1,24 @@ -%h1= api_name +- unless index_view == 'tabular' + %h1= api_name + + - index.resources.each do |resource| + .resource + %h2= resource.name + %ul.examples + - resource.examples.each do |example| + %li.example + = link_to example.description, "/#{example.href}" + +- else + - index.resources.each do |resource| + .resource + %h4= resource.name + %table.table.table-hover + %tbody + - resource.examples.each do |example| + %tr + %td.example_link + = link_to "#{example.http_method.to_s.upcase} #{example.route_url}", "/#{example.href}" + %td.example_description= example.description + -- index.resources.each do |resource| - .resource - %h2= resource.name - %ul.examples - - resource.examples.each do |example| - %li.example - = link_to example.description, "/#{example.href}" diff --git a/lib/views/layout.haml b/lib/views/layout.haml index b79af72..d9eed60 100644 --- a/lib/views/layout.haml +++ b/lib/views/layout.haml @@ -23,9 +23,18 @@ font-size: 130%; } %body + - if index_view == 'tabular' + .navbar.navbar-inverse + .navbar-inner + .container + = link_to api_name, '/', {'class' => "brand"} + .container - .row-fluid - .span4.sidebar - = haml :nav, locals: { index: index, api_name: api_name } - .span8.main - = yield + - if index_view == 'tabular' + = yield + - else + .row-fluid + .span4.sidebar + = haml :nav, locals: { index: index, api_name: api_name } + .span8.main + = yield diff --git a/spec/fixtures/index.json b/spec/fixtures/index.json index 4d768de..fa3fc9c 100644 --- a/spec/fixtures/index.json +++ b/spec/fixtures/index.json @@ -6,12 +6,16 @@ { "description": "Creating an order", "link": "orders/creating_an_order.json", - "groups": "all" + "groups": "all", + "route": "/orders", + "method": "post" }, { "description": "Deleting an order", "link": "orders/deleting_an_order.json", - "groups": "all" + "groups": "all", + "route": "/orders/:id", + "method": "delete" } ] }