Class: HighCarb::Generator

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

Defined Under Namespace

Classes: PathAlreadyExist

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, path) ⇒ Generator

Returns a new instance of Generator.



16
17
18
19
# File 'lib/highcarb/generator.rb', line 16

def initialize(command, path)
  @command = command
  @path = path
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



14
15
16
# File 'lib/highcarb/generator.rb', line 14

def command
  @command
end

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/highcarb/generator.rb', line 13

def path
  @path
end

Instance Method Details

#create_file(path, content) ⇒ Object

Helpers



73
74
75
76
77
# File 'lib/highcarb/generator.rb', line 73

def create_file(path, content)
  puts "Create \033[1m#{path}\033[m"
  path.dirname.mkpath
  path.open "w" do |f| f.write content end
end

#run!Object

Raises:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/highcarb/generator.rb', line 21

def run!
  path = Pathname.new(self.path)
  raise PathAlreadyExist if path.exist?

  create_file path.join("slides/0001.haml"),
    ".slide\n" +
    "  %h1 Title\n" +
    "  Content\n"

  create_file path.join("assets/README"),
    "Put in this directory any file that you want to use in your presentation (images, et al)\n\n" +
    "Files ending with .coffee will be compiled with CoffeeScript.\n" +
    "Files ending with .scss will be compiled with SASS. Compass is available."

  create_file path.join("assets/base.scss"),
    "/*\n * Write here your own styles.\n" +
    " * Compass modules are available\n */\n\n\n" +
    "@import url('/assets/vendor/deck.js/core/deck.core.scss');\n" +
    "@import url('/assets/vendor/deck.js/extensions/goto/deck.goto.scss');\n" +
    "@import url('/assets/vendor/deck.js/extensions/menu/deck.menu.scss');\n" +
    "@import url('/assets/vendor/deck.js/extensions/navigation/deck.navigation.scss');\n" +
    "@import url('/assets/vendor/deck.js/extensions/status/deck.status.scss');\n" +
    "@import url('/assets/vendor/deck.js/extensions/hash/deck.hash.scss');\n" +
    "\n\n/* Choose your favourite deck.js theme */\n" +
    "@import url('/assets/vendor/deck.js/themes/style/swiss.css');\n" +
    "@import url('/assets/vendor/deck.js/themes/transition/horizontal-slide.css');\n"


  create_file path.join("assets/remote.scss"), "/* Add here your styles for the /remote view */"
  create_file path.join("assets/custom-remote.coffee"), "# Add here your own code for the /remote view"
  create_file path.join("assets/custom.coffee"), "# Add here your own code for the views"

  create_file path.join("snippets/README"),
    "Put in this directory any snippet of code that you want to include in your presentation.\n" +
    "You need to install Pygmentize if you want to format the code.\n" +
    "The snippets are loaded with a <snippet>name.rb</snippet> tag.\n" +
    "With Haml, you can use %snippet name.rb\n"

  # Download deck.js, which will include jQuery
  if not command.options["skip-libs"]
    vendor_path = path.join("assets/vendor").expand_path
    vendor_path.mkpath
    Dir.chdir vendor_path do
      puts "Downloading Deck.js into \033[1m#{vendor_path}\033[m..."
      system "curl -L https://github.com/imakewebthings/deck.js/tarball/master | tar xzf -"
      vendor_path.children.first.rename vendor_path.join("deck.js")
    end
  end
end