Sha256: eb4df16425b047f438b5ffc1653a197892cbd5a4ae66e107d2fed49c6bf05928

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

#!/usr/bin/env ruby

require 'pathname'
require 'awesome_print'

class Doc

  attr_reader :data

  def initialize file
    @file = Pathname.new file
    @data = {}
    read
  end

  private

  def read
    comments = []
    last_line = ''

    for line in @file.read.split($/)
      line = line.sub /^\s+/, ''

      if line[0,1] == '#'
        line = '# ```ruby' if line == '# ```' && !comments.include?('```ruby')
        comments.push line.sub('# ', '')
      elsif line.include?('def ') && last_line[0,1] == '#' && comments[0]
        m = line.split(/\s+/)
        @data[m[1]] = comments
        comments = []
      else
        comments = []
      end

      last_line = line
    end
  end
end

components = ['application', 'controller', 'view', 'current', 'mailer', 'config', 'cache', 'error', 'response']

data = []

for c, desc in components
  klass  = 'Lux::%s' % c.capitalize
  readme = Pathname.new 'lib/lux/%s/README.md' % c
  code   = Pathname.new 'lib/lux/%s/%s.rb' % [c, c]

  data << ''
  data << readme.read.sub(/\s+$/, '')

  blocks = Doc.new(code.to_s).data

  if blocks.first
    data << ''
    data << '### %s methods' % klass

    for name, parts in blocks
      data << ''
      data << '#### %s' % name
      data << ''
      data << parts.join($/)
    end
  end
end

out = File.read('lib/README.md')
out += data.join $/

File.write './README.md', out

`rm -rf misc/demo/public/assets`
`rm -rf misc/demo/node_modules`
`rm -rf misc/demo/Gemfile.lock`
`rm -rf misc/demo/package.json`

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lux-fw-0.5.34 ./bin/build_gem
lux-fw-0.5.33 ./bin/build_gem
lux-fw-0.5.32 ./bin/build_gem