stastic 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +11 -0
- data/bin/stastic +11 -1
- data/lib/server.rb +43 -0
- data/lib/stastic/client.rb +72 -0
- data/lib/stastic/command.rb +41 -0
- data/lib/stastic/commands/auth.rb +8 -0
- data/lib/stastic/commands/base.rb +96 -0
- data/lib/stastic/commands/create.rb +68 -0
- data/lib/stastic/commands/domains.rb +41 -0
- data/lib/stastic/commands/help.rb +33 -0
- data/lib/stastic/commands/info.rb +26 -0
- data/lib/stastic/commands/list.rb +37 -0
- data/lib/stastic/commands/preview.rb +9 -0
- data/lib/stastic/commands/publish.rb +34 -0
- data/lib/stastic/commands/rename.rb +25 -0
- data/lib/stastic/commands/set.rb +54 -0
- data/lib/stastic/config.rb +79 -0
- data/lib/stastic/generator.rb +50 -0
- data/lib/stastic/generators/default.rb +31 -0
- data/lib/stastic/generators/jekyll.rb +72 -0
- data/lib/stastic.rb +1 -1
- data/lib/trollop.rb +782 -0
- data/templates/default/index.html +7 -0
- metadata +73 -6
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Stastic
|
4
|
+
module Config
|
5
|
+
extend self
|
6
|
+
|
7
|
+
VALID_SETTINGS = %w(user token name site_id site_root)
|
8
|
+
def exists?
|
9
|
+
File.exists?(config_path) || File.exists?(global_path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def credentials?
|
13
|
+
exists? && user && token
|
14
|
+
end
|
15
|
+
|
16
|
+
def site_defined?
|
17
|
+
credentials? && site_id
|
18
|
+
end
|
19
|
+
|
20
|
+
def update(attrs, scope = nil)
|
21
|
+
if scope == :global
|
22
|
+
@global_config = update_config(attrs, global_config, global_path)
|
23
|
+
else
|
24
|
+
@config = update_config(attrs, config, config_path)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
alias_method :add, :update
|
29
|
+
|
30
|
+
def reset
|
31
|
+
@config = nil
|
32
|
+
@global_config = nil
|
33
|
+
end
|
34
|
+
|
35
|
+
VALID_SETTINGS.each do |key|
|
36
|
+
define_method key do
|
37
|
+
get(key.to_sym)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def update_config(attrs, config_obj, persist_path)
|
43
|
+
updated_config = config_obj.merge(attrs)
|
44
|
+
File.open(persist_path, "w") do |f|
|
45
|
+
f.write(updated_config.to_yaml)
|
46
|
+
end
|
47
|
+
updated_config
|
48
|
+
end
|
49
|
+
|
50
|
+
def stored_config(path)
|
51
|
+
if File.exists?(path)
|
52
|
+
YAML.load(File.read(path))
|
53
|
+
else
|
54
|
+
{}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def get(key)
|
59
|
+
config[key] || global_config[key]
|
60
|
+
end
|
61
|
+
|
62
|
+
def config
|
63
|
+
@config ||= stored_config(config_path)
|
64
|
+
end
|
65
|
+
|
66
|
+
def global_config
|
67
|
+
@global_config ||= stored_config(global_path)
|
68
|
+
end
|
69
|
+
|
70
|
+
def config_path
|
71
|
+
File.expand_path(".stastic")
|
72
|
+
end
|
73
|
+
|
74
|
+
def global_path
|
75
|
+
File.expand_path("~/.stastic")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
Dir["#{File.dirname(__FILE__)}/generators/*.rb"].each { |c| require c }
|
4
|
+
|
5
|
+
module Stastic
|
6
|
+
module Generator
|
7
|
+
extend self
|
8
|
+
|
9
|
+
GENERATOR_TYPES = %w(jekyll default)
|
10
|
+
EXCLUDE_LIST = [
|
11
|
+
".stastic",
|
12
|
+
".git",
|
13
|
+
".svn",
|
14
|
+
".DS_Store",
|
15
|
+
"*.php",
|
16
|
+
"*.rb",
|
17
|
+
"*.haml",
|
18
|
+
"*.sass",
|
19
|
+
"*.pl",
|
20
|
+
"*.py",
|
21
|
+
"*.asp"]
|
22
|
+
|
23
|
+
|
24
|
+
def detect
|
25
|
+
GENERATOR_TYPES.each do |type|
|
26
|
+
generator = eval("Stastic::Generator::#{type.capitalize}")
|
27
|
+
return generator if(generator.send(:detect))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def package(dir)
|
32
|
+
tmpfile = Tempfile.new('st-archive')
|
33
|
+
system "cd #{dir} && tar -cjf #{tmpfile.path} -X #{exclude_file(dir)} . "
|
34
|
+
tmpfile.path
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def exclude_file(dir)
|
40
|
+
tmpfile = Tempfile.new('st-exclude')
|
41
|
+
EXCLUDE_LIST.each do |pattern|
|
42
|
+
tmpfile << "#{pattern}\n"
|
43
|
+
end
|
44
|
+
tmpfile.flush
|
45
|
+
tmpfile.close
|
46
|
+
tmpfile.path
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'server'
|
2
|
+
|
3
|
+
module Stastic::Generator
|
4
|
+
module Default
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def desc
|
8
|
+
"Default Generator"
|
9
|
+
end
|
10
|
+
|
11
|
+
def detect
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def site_root
|
16
|
+
Stastic::Config.site_root || Dir.pwd
|
17
|
+
end
|
18
|
+
|
19
|
+
def build; end
|
20
|
+
|
21
|
+
def package
|
22
|
+
Stastic::Generator.package(site_root)
|
23
|
+
end
|
24
|
+
|
25
|
+
def preview
|
26
|
+
FileUtils.mkdir_p(site_root)
|
27
|
+
server = ::Server.new(site_root, 3000)
|
28
|
+
server.start
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Stastic::Generator
|
2
|
+
module Jekyll
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def desc
|
6
|
+
"Jekyll Generator"
|
7
|
+
end
|
8
|
+
|
9
|
+
def detect
|
10
|
+
FileTest.exists?('_config.yml') ||
|
11
|
+
(FileTest.exists?('_site') && File.directory?('_site'))
|
12
|
+
end
|
13
|
+
|
14
|
+
def site_root
|
15
|
+
Stastic::Config.site_root || "_site"
|
16
|
+
end
|
17
|
+
|
18
|
+
def build
|
19
|
+
verify_gem
|
20
|
+
system("jekyll")
|
21
|
+
end
|
22
|
+
|
23
|
+
def package
|
24
|
+
Stastic::Generator.package(site_root)
|
25
|
+
end
|
26
|
+
|
27
|
+
def preview
|
28
|
+
verify_gem
|
29
|
+
system("jekyll --server")
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def gem_installed?
|
35
|
+
begin
|
36
|
+
gem "jekyll"
|
37
|
+
true
|
38
|
+
rescue LoadError
|
39
|
+
false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def verify_gem
|
44
|
+
if !gem_installed?
|
45
|
+
puts install_instructions
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def install_instructions
|
51
|
+
<<-EOF
|
52
|
+
The Jekyll Gem can not be found on your GEM_PATH.
|
53
|
+
GEM_PATH=#{ENV['GEM_PATH']}
|
54
|
+
|
55
|
+
To Install Jekyll:
|
56
|
+
------------------
|
57
|
+
|
58
|
+
sudo gem install jekyll
|
59
|
+
|
60
|
+
EOF
|
61
|
+
end
|
62
|
+
|
63
|
+
def jekyll_detection_instructions
|
64
|
+
<<-EOF
|
65
|
+
A Jekyll Project was not detected in #{Dir.pwd}
|
66
|
+
|
67
|
+
Stastic looks of _config.yml or _site to detect Jekyll.
|
68
|
+
|
69
|
+
EOF
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/stastic.rb
CHANGED