./lib/doc/doc.rb in joshua-0.2.4 vs ./lib/doc/doc.rb in joshua-0.2.7

- old
+ new

@@ -1,10 +1,12 @@ class Joshua module Doc extend self - ICONS = { + HtmlTag self + + ICONS ||= { github: { url: 'https://github.com/dux/joshua', image: '<path d="M11.999 1.271C5.925 1.271 1 6.196 1 12.273c0 4.859 3.152 8.982 7.523 10.437.55.1.751-.239.751-.53l-.015-1.872c-3.06.666-3.706-1.474-3.706-1.474-.5-1.271-1.221-1.609-1.221-1.609-.999-.683.075-.668.075-.668 1.105.077 1.685 1.133 1.685 1.133.981 1.681 2.575 1.196 3.202.914.1-.711.384-1.196.698-1.471-2.442-.277-5.011-1.221-5.011-5.436 0-1.201.429-2.183 1.133-2.952-.114-.278-.491-1.397.108-2.911 0 0 .923-.296 3.025 1.127A10.56 10.56 0 0 1 12 6.591c.935.004 1.876.127 2.754.37 2.1-1.423 3.022-1.127 3.022-1.127.6 1.514.223 2.633.11 2.911.705.769 1.131 1.751 1.131 2.952 0 4.225-2.573 5.155-5.023 5.427.395.34.747 1.011.747 2.038 0 1.471-.014 2.657-.014 3.018 0 .293.199.636.756.528C19.851 21.251 23 17.13 23 12.273c0-6.077-4.926-11.002-11.001-11.002z"></path>', }, twitter: { @@ -19,42 +21,38 @@ url: 'https://github.com/dux/joshua/issues', image: '<path d="M3,4v12c0,1.103,0.897,2,2,2h3.5l3.5,4l3.5-4H19c1.103,0,2-0.897,2-2V4c0-1.103-0.897-2-2-2H5C3.897,2,3,2.897,3,4z M11,5 h2v6h-2V5z M11,13h2v2h-2V13z" />' } } - def tag - HtmlTagBuilder - end - def misc_file name File.read [__dir__, '../misc/%s' % name].join('/') end # render full page def render mount_on: nil, request: nil, bearer: nil mount_on ||= request.url.split('?').first+'/' mount_on.sub! %r{//$}, '/' - tag.html do |n| - n.head do |n| + HtmlTag.html do |n| + n.tag(:head) do |n| n.title 'Joshua Tester' n.link({ href: "https://fonts.googleapis.com/css?family=Inter:300,400,500,600,700,800,900&display=swap", rel:"stylesheet" }) n.link({ rel:"stylesheet", href:"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" }) n.script({ src: 'https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js' }) n.script %[window.api_opts = { mount_on: '#{mount_on}', bearer: '#{bearer}' }] end - n.body do |n| + n.tag(:body) do |n| n.style { misc_file('doc.css') } n.header({ style: 'border-bottom: 1px solid rgb(228, 228, 228);'}) do |n| n._container do |n| n.push top_icons n.push %[<button id="bearer_button" onclick="AuthButton.set()" class="btn btn-sm btn-outline-primary" style="float: right; margin-top: 15px; margin-right: 20px;">-</button>] n.h1({ class: :nav}) { %[<a href="#top">Joshua &nbsp; <gray>Docs</gray></a>] } end end - n.img src:"https://i.imgur.com/HWoUz5k.png", style: 'width: 40px; z-index: 1; position: absolute; top: 10px; left: 50%;', onclick: "window.open('https://github.com/dux/joshua')" + n.img src:"https://camo.githubusercontent.com/4b5b5447d6af920f58a030740bc8e9cf52dc490a8a560492c6ad3a5c6a0ad076/68747470733a2f2f692e696d6775722e636f6d2f48576f557a356b2e706e67", style: 'width: 40px; z-index: 1; position: absolute; top: 10px; left: 50%;', onclick: "window.open('https://github.com/dux/joshua')" n.push modal_dialog n._container do |n| n._row do |n| @@ -75,12 +73,12 @@ n.br n.p '<b>API LIBRARIES</b>' n.div do |n| - n.push %[<a class="badge badge-light" href="https://github.com/dux/joshua/blob/master/lib/client/ruby/client" target="capi_ruby">Ruby</a>] - n.push %[<a class="badge badge-light" href="https://github.com/dux/joshua/blob/master/lib/misc/api_example.coffee" target="capi_js">Javascript</a>] + n.push %[<a class="badge badge-light" href="https://github.com/dux/joshua/tree/master/client/ruby" target="capi_ruby">Ruby</a>] + n.push %[<a class="badge badge-light" href="https://github.com/dux/joshua/tree/master/client/javascript" target="capi_js">Javascript</a>] n.push %[<a class="badge badge-light" href="#">Python</a>] n.push %[<a class="badge badge-light" href="#">C#</a>] end n.br @@ -112,21 +110,21 @@ %[<svg style="width: #{size}px; height: #{size}px; #{style}" viewBox="0 0 24 24" fill="currentColor">#{data}</svg>] end # top side navigation icons def top_icons - tag.div({ style: 'float: right; margin-top: 18px;' }) do |n| + tag.div style: 'float: right; margin-top: 18px;' do for icon in ICONS.values next unless icon[:url] - n.push %[<a target="_new" href="#{icon[:url]}">#{icon icon[:image]}</a>] + a icon(icon[:image]), target: '_new', href: icon[:url] end end end # left side navigation def left_nav - tag.div do |n| + HtmlTag.div do |n| Joshua.documented.each do |name| n.a({ class:'btn btn-outline-info btn-sm', style: '-font-size: 14px; margin-bottom: 10px;', href: '#%s' % name}) do |n| icon = name.opts.dig(:opts, :icon) n.push self.icon icon, size: 20 if icon n.push name.to_s.sub(/Api$/, '') @@ -137,11 +135,11 @@ end end # render doc for all documented classes def index - tag.div do |n| + HtmlTag.div do |n| for @klass in Joshua.documented @opts = @klass.opts icon = @opts.dig(:opts, :icon) n._sticky(style: 'background: #f7f7f7; padding-bottom: 5px; padding-top: 30px; margin-top: 2px;') do |n| @@ -170,11 +168,11 @@ # render members or collection def render_type name base = @opts[name] || return - tag.div do |n| + HtmlTag.div do |n| n.br n.h5 '<gray>%s methods</gray>' % name for m_name, member in base n.div do |n| @@ -184,27 +182,20 @@ end end # render api method def render_method name:, m_name:, opts: - tag._box do |n| + HtmlTag._box do |n| # n.push %[<button onclick="" class="btn btn-info btn-sm request">request</button>] anchor = [@klass, m_name].join('-') n.push name_link anchor - n.h5 do |n| + n.h5 style: 'margin-bottom: 20px;' do |n| n.push "<a href='##{anchor}'>#{m_name}</a>" n.push ' <gray>&nbsp; &mdash; &nbsp; %s</gray>' % opts[:desc] if opts[:desc] end - n.p({style: 'margin: 20px 0 25px 0;'}) do |n| - path = @klass.api_path - path += '/:id' if name == :member - path += "/#{m_name}" - n.push %[<button href="#{path}" class="btn btn-outline-info btn-sm" onclick="ModalForm.render(api_opts.mount_on+this.innerHTML, #{(opts[:params] || {}).to_json.gsub('"', '&quot;')})">#{path}</button>] - end - if opts[:detail] n.h6 'Details' n.pre opts[:detail] end @@ -222,15 +213,22 @@ n.push ' &mdash; (%s)' % data.join(', ') if data.length > 0 end end end end + + n.p style: 'margin: 30px 0 10px 0;' do |n| + path = @klass.api_path + path += '/:id' if name == :member + path += "/#{m_name}" + n.push %[<button href="#{path}" class="btn btn-outline-info btn-sm" onclick="ModalForm.render(api_opts.mount_on+this.innerHTML, #{(opts[:params] || {}).to_json.gsub('"', '&quot;')})">#{path}</button>] + end end end def list_errors - tag.div do |n| + HtmlTag.div do |n| n.push name_link :api_errors n.push icon ICONS[:error][:image], style: 'position: absolute; margin-left: -40px; margin-top: 1px; fill: #777;' n.h4 { 'Named errors' } n._box do |n| @@ -271,6 +269,6 @@ </div> </div> ] end end -end \ No newline at end of file +end