Class: Rouge::CLI::Style

Inherits:
Rouge::CLI show all
Defined in:
lib/rouge/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rouge::CLI

class_from_arg, #error!, error!

Constructor Details

#initialize(opts) ⇒ Style

Returns a new instance of Style.



429
430
431
432
433
434
435
436
437
438
439
# File 'lib/rouge/cli.rb', line 429

def initialize(opts)
  theme_name = opts.delete(:theme_name)
  theme_class = Theme.find(theme_name) \
    or error! "unknown theme: #{theme_name}"

  @theme = theme_class.new(opts)
  if opts[:tex]
    tex_prefix = opts[:tex_prefix]
    @theme = TexThemeRenderer.new(@theme, prefix: tex_prefix)
  end
end

Class Method Details

.descObject



380
381
382
# File 'lib/rouge/cli.rb', line 380

def self.desc
  "print CSS styles"
end

.doc {|%|usage: rougify style [<theme-name>] [<options>]|| ... } ⇒ Object

Yields:

  • (%|usage: rougify style [<theme-name>] [<options>]|)


384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/rouge/cli.rb', line 384

def self.doc
  return enum_for(:doc) unless block_given?

  yield %|usage: rougify style [<theme-name>] [<options>]|
  yield %||
  yield %|Print CSS styles for the given theme.  Extra options are|
  yield %|passed to the theme. To select a mode (light/dark) for the|
  yield %|theme, append '.light' or '.dark' to the <theme-name>|
  yield %|respectively. Theme defaults to thankful_eyes.|
  yield %||
  yield %|options:|
  yield %|  --scope     	(default: .highlight) a css selector to scope by|
  yield %|  --tex       	(default: false) render as TeX|
  yield %|  --tex-prefix	(default: RG) a command prefix for TeX|
  yield %|              	implies --tex if specified|
  yield %||
  yield %|available themes:|
  yield %|  #{Theme.registry.keys.sort.join(', ')}|
end

.parse(argv) ⇒ Object



404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/rouge/cli.rb', line 404

def self.parse(argv)
  opts = {
    :theme_name => 'thankful_eyes',
    :tex => false,
    :tex_prefix => 'RG'
  }

  until argv.empty?
    arg = argv.shift
    case arg
    when '--tex'
      opts[:tex] = true
    when '--tex-prefix'
      opts[:tex] = true
      opts[:tex_prefix] = argv.shift
    when /--(\w+)/
      opts[$1.tr('-', '_').to_sym] = argv.shift
    else
      opts[:theme_name] = arg
    end
  end

  new(opts)
end

Instance Method Details

#runObject



441
442
443
# File 'lib/rouge/cli.rb', line 441

def run
  @theme.render(&method(:puts))
end