Skip to content

Instantly share code, notes, and snippets.

@jch
Created July 2, 2012 18:17
Show Gist options
  • Select an option

  • Save jch/3034703 to your computer and use it in GitHub Desktop.

Select an option

Save jch/3034703 to your computer and use it in GitHub Desktop.

Revisions

  1. jch revised this gist Jul 2, 2012. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion yard-mount.rb
    Original file line number Diff line number Diff line change
    @@ -50,4 +50,8 @@
    # General rack application. If there's a .yardoc directory in the same
    # directory as .config.ru, then default the lib name to the directory name,
    # and default options to `{single_library: true, caching: false}`
    use YARD::Server::RackMiddleware
    use YARD::Server::RackMiddleware
    run YourApp

    # or... also gives defaults if .yardoc is detected
    run YARD::Server::RackAdapter
  2. jch revised this gist Jul 2, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion yard-mount.rb
    Original file line number Diff line number Diff line change
    @@ -50,4 +50,4 @@
    # General rack application. If there's a .yardoc directory in the same
    # directory as .config.ru, then default the lib name to the directory name,
    # and default options to `{single_library: true, caching: false}`
    use YARD::Server::RackAdapter
    use YARD::Server::RackMiddleware
  3. jch revised this gist Jul 2, 2012. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion yard-mount.rb
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,6 @@
    :caching => false
    })


    Surfiki::Application.routes.draw do
    mount docs => '/doc', anchor: false

  4. jch revised this gist Jul 2, 2012. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions yard-mount.rb
    Original file line number Diff line number Diff line change
    @@ -28,6 +28,15 @@
    # /js/live.js and /css/custom.css. Is there a way to prefix
    # all the generated docs with '/doc'?
    # config/routes.rb

    doc_server = YARD::Server::RackAdapter.new(
    {'surfiki' => [YARD::Server::LibraryVersion.new('surfiki', nil, File.expand_path('../../.yardoc', __FILE__))]},
    {
    :single_library => true,
    :caching => false
    })


    Surfiki::Application.routes.draw do
    mount docs => '/doc', anchor: false

  5. jch created this gist Jul 2, 2012.
    45 changes: 45 additions & 0 deletions yard-mount.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    # 1) Running a raw RackAdapter in config.ru mounted at '/' works fine
    require 'bundler/setup'
    require 'yard'

    run YARD::Server::RackAdapter.new(
    {'surfiki' => [YARD::Server::LibraryVersion.new('surfiki', nil, File.expand_path('../.yardoc', __FILE__))]},
    {
    :single_library => true,
    :caching => false
    })

    # 2) Mapping the adapter to a path fails because
    # the request path will be anchored at '/yard'
    map '/yard' do
    # This will return 404, X-CASCADE: pass and go downstream
    run YARD::Server::RackAdapter.new(
    {'surfiki' => [YARD::Server::LibraryVersion.new('surfiki', nil, File.expand_path('../.yardoc', __FILE__))]},
    {
    :single_library => true,
    :caching => false
    })
    end

    run Surfiki::Application # downstream rails app

    # 3) Using Rail's `mount` helper in routes.rb will serve up the proper html,
    # but the generated docs will reference top level assets like
    # /js/live.js and /css/custom.css. Is there a way to prefix
    # all the generated docs with '/doc'?
    # config/routes.rb
    Surfiki::Application.routes.draw do
    mount docs => '/doc', anchor: false

    # snip...
    end

    # 4) Proposed changes for mounting docs alongside another rack app. This
    # change would be more for convenience and would be backwards compatible
    # with the old interface. Additionally, change the default routing behavior
    # to not anchor paths, but allow an option `:anchor` for configuration

    # General rack application. If there's a .yardoc directory in the same
    # directory as .config.ru, then default the lib name to the directory name,
    # and default options to `{single_library: true, caching: false}`
    use YARD::Server::RackAdapter