Sha256: a2963a2f1a3c42e3feb86bf167502f03a1759f878c5c929aefeee5267b93283a

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

command 'render' do |c|
  c.syntax = 'brief render PATH [OPTIONS]'
  c.description = 'render the briefcase path'

  c.option '--root PATH', String, 'The briefcase root'
  c.option '--output PATH', String, 'Save the output to the specified path'
  c.option '--app APP', String, 'Use the specified app to get our models etc'
  c.option '--config PATH', String, 'Use the specified config file'
  c.option '--include-raw', nil, 'Whether or not to include the raw content'

  c.action do |args, options|
    options.default(root: Pathname(Brief.pwd))

    o = {
      root: options.root
    }

    o[:app] = options.app if options.app
    o[:config_path] = options.config if options.config

    briefcase = Brief::Briefcase.new(o)

    index = 0

    rendered = if args.empty?
      briefcase.all_models.map do |model|
        model.document.to_html(script: true, content: !!(options.include_raw), skip_preamble: (index += 1) > 1)
      end
    else
      args.map do |a|
        Dir[briefcase.root.join(a)].map do |f|
          doc = Brief::Document.new(f).in_briefcase(briefcase)
          doc.to_html(script: true, content: !!(options.include_raw), skip_preamble: (index += 1) > 1)
        end
      end.flatten
    end

    html = rendered.join("\n")
    html = "<html><head></head><body class='brief-export #{options[:app]}'>#{html}</body></html>"
    if options.output
      Pathname(options.output).open("w+") do |fh|
        fh.write(html)
      end
    else
      puts html
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
brief-1.8.9 lib/brief/cli/render.rb
brief-1.8.8 lib/brief/cli/render.rb