Class: Redcarpeter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/redcarpeter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.



18
19
20
21
22
23
24
25
# File 'lib/redcarpeter.rb', line 18

def initialize *args
  @args = args.flatten

  @input = @args.first

  @extension = File.extname(@input)
  @filename = File.basename(@input, @extension)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



16
17
18
# File 'lib/redcarpeter.rb', line 16

def args
  @args
end

#extensionObject (readonly)

Returns the value of attribute extension.



16
17
18
# File 'lib/redcarpeter.rb', line 16

def extension
  @extension
end

#filenameObject (readonly)

Returns the value of attribute filename.



16
17
18
# File 'lib/redcarpeter.rb', line 16

def filename
  @filename
end

#inputObject (readonly)

Returns the value of attribute input.



16
17
18
# File 'lib/redcarpeter.rb', line 16

def input
  @input
end

Class Method Details

.compile(*args) ⇒ Object



28
29
30
# File 'lib/redcarpeter.rb', line 28

def compile *args
  new(args).compile!
end

Instance Method Details

#compile!Object



37
38
39
40
41
# File 'lib/redcarpeter.rb', line 37

def compile!
  File.open("#{filename}.html", 'w') do |file| 
    file.write(markdown.to_html)
  end
end

#markdownObject



33
34
35
# File 'lib/redcarpeter.rb', line 33

def markdown
  @markdown ||= Redcarpet.new(File.read(@input))
end