mdss 0.0.2 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/bin/mdss +53 -24
  3. data/lib/mdss.rb +18 -0
  4. data/lib/mdss/extra.rb +15 -0
  5. data/lib/mdss/init.rb +61 -6
  6. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5354d94d40bb66c80e19d4e62820b2bad52797a3
4
- data.tar.gz: 79e62eedde82a8d04861b47821903f7afb6d9665
3
+ metadata.gz: cbed64f120fd840779dd3b7e849332ae271586b0
4
+ data.tar.gz: eb6ea75a7b04e741c6acd98088ac4fba263c10f6
5
5
  SHA512:
6
- metadata.gz: cd1209af3bea5415ebadc0360495269bb075bc7e70c286564ce3de58711532720fede7d8d35b660e7295bad4571f3c33e66e27dd735365a7c02bb7afa0acfe0d
7
- data.tar.gz: 8832b5e6da8e84dbf9fd9832edb2be20bf5ce8fa767b12484c90d2ad8c02dbaecabefd44912c68486b0bde76a7fe17d29b067b4c060918ec5eab39e00acaaaa4
6
+ metadata.gz: a09149b888957f667fcc44aa57b6332105746eea176eb7abd0e52622eba0b1b0742409da34c8a27a456bf3ebdaaae736d7df29ace311e98e8744b7d529be82d9
7
+ data.tar.gz: 90efdd284681369ba024ba1d0fbb60e126d98eced12f9e01f674860d3fd5e5af4b8916e8ae8ec2b4da928a7473e5f12851ea4a63bf09a0c1c66dc7b520117687
data/bin/mdss CHANGED
@@ -1,35 +1,64 @@
1
1
  #!/usr/bin/env ruby
2
+ # To parse command line args
2
3
  require 'optparse'
4
+ # MDSS code
3
5
  require 'mdss'
4
6
 
5
- options = {:name => nil, :launch => false}
6
- mdss_helper = MDSS.get_extra
7
+ =begin rdoc
8
+ Wrapper class around the CLI functionality of MDSS.
9
+ =end
10
+ class MDSSCLI
11
+ =begin rdoc
12
+ call-seq:
13
+ MDSSCLI.start => nil
7
14
 
8
- parser = OptionParser.new do |opts|
9
- opts.banner = "Usage: mdss [options]"
15
+ Start the MDSS CLI. The arguments provided are parsed using the OptionParser class.
16
+ =end
17
+ def self.start
18
+ # Define our option parameters. We need the name of the site, or if we are
19
+ # launching the site to a server
20
+ options = {:name => nil, :launch => false}
21
+ # Some helper functions
22
+ mdss_helper = MDSS.get_extra
10
23
 
11
- opts.on("-i", "--init <NAME>", "Create a new simple static site with GFM") do |name|
12
- options[:name] = name
13
- end
24
+ # Define our various options
25
+ parser = OptionParser.new do |opts|
26
+ opts.banner = "Usage: mdss [options]"
14
27
 
15
- opts.on("-l", "--launch", "Compile and upload to the big wide world") do
16
- options[:launch] = true
17
- exit
18
- end
28
+ # Initialize a new site
29
+ opts.on("-i", "--init <NAME>", "Create a new simple static site with GFM") do |name|
30
+ options[:name] = name
31
+ end
19
32
 
20
- opts.on("-h", "--help", "Display help menu") do
21
- puts opts
22
- exit
23
- end
24
- end
33
+ # Launching an existing site to a server
34
+ opts.on("-l", "--launch", "Compile and upload to the big wide world") do
35
+ options[:launch] = true
36
+ exit
37
+ end
25
38
 
26
- begin parser.parse!
27
- rescue OptionParser::MissingArgument => e
28
- mdss_helper.puts_err("Missing site name")
29
- end
39
+ # Display the help menu
40
+ opts.on("-h", "--help", "Display help menu") do
41
+ puts opts
42
+ exit
43
+ end
44
+ end
45
+
46
+ # Parse the arguments, catching any errors
47
+ begin parser.parse!
48
+ rescue OptionParser::MissingArgument => e
49
+ mdss_helper.puts_err("Missing site name")
50
+ end
30
51
 
31
- if options[:launch]
32
- mdss_helper.puts_err("Unsupported behavior")
33
- else
34
- MDSS.mdss_init options[:name]
52
+ # Looks like we're launching to a server
53
+ if options[:launch]
54
+ mdss_helper.puts_err("Unsupported behavior")
55
+ # Looks like we're making a new site
56
+ else
57
+ # Pass the site name to the initalizer function
58
+ MDSS.mdss_init options[:name]
59
+ end
60
+ end
35
61
  end
62
+
63
+ # Start the CLI
64
+ MDSSCLI.start
@@ -1,11 +1,29 @@
1
+ # Get our helper functions
1
2
  require 'mdss/extra'
3
+ # Get the MDSS initializer
2
4
  require 'mdss/init'
3
5
 
6
+ =begin rdoc
7
+ MDSS will serve as the main class for the gem, providing the hooks to the inner working classes as needed.
8
+ =end
4
9
  class MDSS
10
+
11
+ =begin rdoc
12
+ call-seq:
13
+ MDSS.get_extra => MDSSExtra
14
+
15
+ Provides an instance of MDSSExtra for helper functions throughout the MDSS gem.
16
+ =end
5
17
  def self.get_extra
6
18
  MDSSExtra.new
7
19
  end
8
20
 
21
+ =begin rdoc
22
+ call-seq:
23
+ MDSS.mdss_init(name) => nil
24
+
25
+ Creates a new simple static site in the directory specified by name. If the directory exists, it will attempt to setup a simple static site within it anyway.
26
+ =end
9
27
  def self.mdss_init(name)
10
28
  MDSSInit.mdss_init name
11
29
  end
@@ -1,8 +1,23 @@
1
+ =begin rdoc
2
+ Wrapper class around helper methods.
3
+ =end
1
4
  class MDSSExtra
5
+ =begin rdoc
6
+ call-seq:
7
+ puts_warn(err) => nil
8
+
9
+ Output a warning message to STDOUT.
10
+ =end
2
11
  def puts_warn(err)
3
12
  puts "WARNING: #{err}"
4
13
  end
5
14
 
15
+ =begin rdoc
16
+ call-seq:
17
+ puts_err(err) => nil
18
+
19
+ Output an error message to STDOUT and terminate.
20
+ =end
6
21
  def puts_err(err)
7
22
  puts "ERROR: #{err}. Terminating"
8
23
  exit
@@ -1,13 +1,68 @@
1
+ # To create empty files
2
+ require 'fileutils'
3
+ # For helper methods
1
4
  require_relative 'extra'
2
5
 
6
+ =begin rdoc
7
+ MDSSInit serves to create new simple static sites.
8
+ =end
3
9
  class MDSSInit
10
+ # Instance of our helper methods class
11
+ @@helper = MDSSExtra.new
12
+
13
+ =begin rdoc
14
+ call-seq:
15
+ MDSSInit.mdss_init(name) => nil
16
+
17
+ Create a new simple static site in the directory specified by name. If a directory with the specified name exists, it tries to create the necessary files and directories with #init_dir.
18
+ =end
4
19
  def self.mdss_init(name)
5
- MDSSExtra.new.puts_err("Directory exists") if File.exists?(name)
6
-
7
- Dir.mkdir(name)
20
+ if File.exists?(name)
21
+ MDSSExtra.new.puts_warn("Directory exists")
22
+ else
23
+ Dir.mkdir(name)
24
+ end
25
+
26
+ self.init_file(name, ".mdss.cfg", ["name=#{name}"])
27
+ self.init_file(name, "index.md")
28
+
29
+ self.init_dir(name, "css", "CSS", "styles.css")
30
+ self.init_dir(name, "js", "JavaScript", "scripts.js")
31
+ self.init_dir(name, "img", "Image")
32
+ end
33
+
34
+ =begin rdoc
35
+ call-seq:
36
+ MDSSInit.init_dir(name, dirname, warn) => nil
37
+ MDSSInit.init_dir(name, dirname, warn, file) => nil
38
+
39
+ Create a new directory for the simple static site. warn is used to specify the name of the folder for the warning message if the directory specified by dirname exists. If a filename is specified, that file is created within the directory.
40
+ =end
41
+ def self.init_dir(name, dirname, warn, file = nil)
42
+ if File.exists?("#{name}/#{dirname}")
43
+ helper.puts_warn("#{warn} folder exists, skipping")
44
+ else
45
+ Dir.mkdir("#{name}/#{dirname}")
46
+ FileUtils.touch("#{name}/#{dirname}/#{file}") unless file.nil?
47
+ end
48
+ end
49
+
50
+ =begin rdoc
51
+ call-seq:
52
+ MDSSInit.init_file(name, file) => nil
53
+ MDSSInit.init_file(name, file, contents) => nil
8
54
 
9
- File.open("#{name}/.mdss.cfg", 'w+') do |cfg|
10
- cfg.write("name=#{name}")
11
- end
55
+ Create a new file in the parent directory for the site. If contents are specified as an array of strings, they are written to the file, else a blank file is created.
56
+ =end
57
+ def self.init_file(name, file, contents = nil)
58
+ if contents.nil?
59
+ FileUtils.touch("#{name}/#{file}")
60
+ else
61
+ File.open("#{name}/#{file}", "w+") do |file|
62
+ contents.each do |line|
63
+ file.write(line)
64
+ end
65
+ end
66
+ end
12
67
  end
13
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryce Davis