Sha256: ef79c6555fec400e4d40e4db0e3bc810588cf2997c0563ccd1779a9f09696d0a

Contents?: true

Size: 1.88 KB

Versions: 35

Compression:

Stored size: 1.88 KB

Contents

module YARD
  module CLI
    # Display one object
    # @since 0.8.6
    class Display < Yardoc
      def description; 'Displays a formatted object' end

      def initialize(*args)
        super
        options.format = :text # default for this command
        @layout = nil
        @objects = []
      end

      # Runs the commandline utility, parsing arguments and displaying an object
      # from the {Registry}.
      #
      # @param [Array<String>] args the list of arguments.
      # @return [void]
      def run(*args)
        return unless parse_arguments(*args)
        log.puts wrap_layout(format_objects)
      end

      # @return [String] the output data for all formatted objects
      def format_objects
        @objects.inject([]) do |arr, obj|
          arr.push obj.format(options)
        end.join("\n")
      end

      def wrap_layout(contents)
        return contents unless @layout
        opts = options.merge(
          :contents => contents,
          :object => @objects.first,
          :objects => @objects
        )
        args = [options.template, @layout, options.format]
        Templates::Engine.template(*args).run(opts)
      end

      # Parses commandline options.
      # @param [Array<String>] args each tokenized argument
      def parse_arguments(*args)
        opts = OptionParser.new
        opts.banner = "Usage: yard display [options] OBJECT [OTHER OBJECTS]"
        general_options(opts)
        output_options(opts)
        parse_options(opts, args)

        Registry.load
        @objects = args.map {|o| Registry.at(o) }

        # validation
        return false if @objects.any? {|o| o.nil? }
        verify_markup_options
      end

      def output_options(opts)
        super(opts)
        opts.on('-l', '--layout [LAYOUT]', 'Wraps output in layout template (good for HTML)') do |layout|
          @layout = layout || 'layout'
        end
      end
    end
  end
end

Version data entries

35 entries across 31 versions & 7 rubygems

Version Path
abaci-0.3.0 vendor/bundle/gems/yard-0.9.2/lib/yard/cli/display.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.1/lib/yard/cli/display.rb
yard-0.9.5 lib/yard/cli/display.rb
yard-0.9.4 lib/yard/cli/display.rb
yard-0.9.3 lib/yard/cli/display.rb
yard-0.9.2 lib/yard/cli/display.rb
yard-0.9.1 lib/yard/cli/display.rb
yard-0.9.0 lib/yard/cli/display.rb
yard-0.8.7.6 lib/yard/cli/display.rb
yard-0.8.7.5 lib/yard/cli/display.rb
climine-0.0.7 vendor/bundle/ruby/2.1.0/gems/yard-0.8.7.3/lib/yard/cli/display.rb
climine-0.0.7 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/cli/display.rb
climine-0.0.6 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/cli/display.rb
climine-0.0.5 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/cli/display.rb
yard-0.8.7.4 lib/yard/cli/display.rb
climine-0.0.4 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/cli/display.rb
climine-0.0.3 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/cli/display.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/yard-0.8.7.3/lib/yard/cli/display.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/cli/display.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/cli/display.rb