Skip to content

Commit

Permalink
Merge pull request #5 from NDrive/add-recursive-folder-doc-reader
Browse files Browse the repository at this point in the history
Enables read files inside folders
  • Loading branch information
Vladimir Krylov committed Dec 4, 2014
2 parents 4f81dc5 + 3b4ba7b commit f4eaa86
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/api_docs/views/_controller_index.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%div
= preserve do
:markdown
#{File.read(File.join(ApiDocs.config.docs_path.join("#{controller}.md")))}
#{mardown_data}
14 changes: 7 additions & 7 deletions lib/api_docs/views/index.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@
%ul.nav.nav-list#api-doc-nav
- controllers.each_with_index do |(controller, actions), ci|
%li.nav-header{:class => (ci == 0) ? 'active' : ''}
- if markdown_not_exist?(controller)
- if actions.header_content.nil?
=controller.gsub(/\W/, '_').humanize.titleize
- else
%a{ href: "##{controller.gsub(/\W/, '_')}", :data => {:toggle => 'tab'} }= controller.gsub(/\W/, '_').humanize.titleize
- actions.each_with_index do |(action, data), ai|
%li{:class => (ci == 0 && ai == 0 && markdown_not_exist?(controller)) ? 'active' : ''}
- actions.content.each_with_index do |(action, data), ai|
%li{:class => (ci == 0 && ai == 0 && actions.header_content.nil?) ? 'active' : ''}
- tab_id = "#{controller.gsub(/\W/, '_')}_#{action}"
%a{ href: "##{tab_id}", :data => {:toggle => 'tab'} }= action.humanize.titleize
.span10
.tab-content
- controllers.each_with_index do |(controller, actions), ci|
- actions.each_with_index do |(action, data), ai|
- actions.content.each_with_index do |(action, data), ai|
- tab_id = "#{controller.gsub(/\W/, '_')}_#{action}"
.tab-pane{:id => tab_id, :class => (ci == 0 && ai == 0 && markdown_not_exist?(controller)) ? 'active' : ''}
.tab-pane{:id => tab_id, :class => (ci == 0 && ai == 0 && actions.header_content.nil?) ? 'active' : ''}
- data.each do |_, data|
= haml :_action, locals: {action: data}
- tab_global = "#{controller.gsub(/\W/, '_')}"
- unless markdown_not_exist?(controller)
- if actions.header_content.present?
.tab-pane{:id => tab_global, :class => (ci == 0) ? 'active' : ''}
= haml :_controller_index, locals: {controller: controller}
= haml :_controller_index, locals: {mardown_data: actions.header_content}
19 changes: 16 additions & 3 deletions lib/api_docs/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Web < Sinatra::Base
helpers do
def controllers
@controllers ||= begin
Dir.glob(ApiDocs.config.docs_path.join('*.yml')).sort.inject({}) do |memo, file_path|
memo[File.basename(file_path, '.yml')] = YAML.load_file(file_path)
Dir.glob(ApiDocs.config.docs_path.join('**/*.yml')).sort.inject({}) do |memo, file_path|
memo[File.basename(file_path, '.yml')] = Content.new(file_path)
memo
end
end
Expand Down Expand Up @@ -48,7 +48,20 @@ def markdown_not_exist? controller_name
get '/' do
haml :index
end

end

class Content < Struct.new(:file_path)
def content
YAML.load_file(file_path)
end

def header_content
File.exist?(markdown_path) ? File.read(markdown_path) : nil
end

private
def markdown_path
file_path.gsub(File.extname(file_path), ".md")
end
end
end

0 comments on commit f4eaa86

Please sign in to comment.