Sha256: ffc8afec1196cdd8c5b045883ffacac4821e45d16eb0f4616fa51d874cef7b41

Contents?: true

Size: 1.21 KB

Versions: 6

Compression:

Stored size: 1.21 KB

Contents

module SmallCage::Commands
  class Uri
    def self.execute(opts)
      new(opts).execute
    end

    def initialize(opts)
      @opts = opts
    end

    def execute
      target = Pathname.new(@opts[:path])
      fail 'target directory or file does not exist.: ' + target.to_s unless target.exist?

      @loader   = SmallCage::Loader.new(target)
      @renderer = SmallCage::Renderer.new(@loader)
      print_uris
    end

    def print_uris
      @loader.each_smc_obj do |obj|
        print_default_or_template_uris(obj)
      end
    end
    private :print_uris

    def print_default_or_template_uris(obj)
      uris = @renderer.render(obj['template'] + '.uri', obj)
      if uris
        print_uri_templates(obj, uris.split(/\r\n|\r|\n/))
      else
        puts obj['uri']
      end
    end
    private :print_default_or_template_uris

    def print_uri_templates(obj, uris)
      uris = uris.map { |uri| uri.strip }
      base = obj['path'].parent
      uris.each_with_index do |uri, index|
        if uri.empty?
          puts ''
        else
          docpath = SmallCage::DocumentPath.create_with_uri(@loader.root, uri, base)
          puts docpath.uri
        end
      end
    end
    private :print_uri_templates
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
smallcage-0.3.2 lib/smallcage/commands/uri.rb
smallcage-0.3.1 lib/smallcage/commands/uri.rb
smallcage-0.3.0 lib/smallcage/commands/uri.rb
smallcage-0.2.9 lib/smallcage/commands/uri.rb
smallcage-0.2.8 lib/smallcage/commands/uri.rb
smallcage-0.2.7 lib/smallcage/commands/uri.rb