77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/mkmatter/cli/subs/new.rb', line 77
def post
if options[:draft] and options[:file]
if Mkmatter::Methods.check_if_jekyll
@questions = Mkmatter::Questions::Post.new(HILINE).ask
answers = Mkmatter::Answers.new(@questions, options[:publish])
file_folder = '_drafts'
filename = [].concat([answers.slug_date, '-', answers.title.to_slug, '.', answers.file_format.downcase]).join
path = Pathname("./#{file_folder}/#{filename}").realdirpath
if HILINE.agree('Would you like to put this page into a subdirectory?', true)
HILINE.say("What path? (directories will be created if they don't exist)")
HILINE.say("Don't use a path starting with a slash, just put a relative path.")
HILINE.say("<% Paint['Good', 'green', :bold] %>: path/to/dir ‖ <%= color('Bad', 'red', :bold) %>: /root/paths/are/bad/mmkay")
folder = HILINE.ask('? ') do |q|
q.confirm = true
q.default = '.'
q.validate = /^[^\/].*$/
end
folder = Pathname(folder)
begin
FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder))
rescue Errno::EEXIST
HILINE.say("<% Paint['Error', 'red', :bold] %>:Insufficient Permissions")
exit 1
end
path = Pathname(folder).realdirpath.join(filename)
end
File.open(path.to_path, 'a') do |fd|
answers.to_h = {:layout => 'post'}
fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
fd.puts '---'
end
Mkmatter::Methods.launch_editor(options[:editor], path)
else
puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)"
exit 1
end
elsif options[:file] and options[:draft].nil? or options[:draft] == false
if Mkmatter::Methods.check_if_jekyll
@questions = Mkmatter::Questions::Post.new(HILINE).ask
answers = Mkmatter::Answers.new(@questions, options[:publish])
file_folder = '_posts'
filename = [].concat([answers.slug_date, '-', answers.title.to_slug, '.', answers.file_format.downcase]).join('')
path = Pathname("./#{file_folder}/#{filename}").realdirpath
if HILINE.agree('Would you like to put this post into a subdirectory?', true)
HILINE.say('What path?')
HILINE.say('----------------')
HILINE.say("Don't use a path starting with a slash, just put a relative path.")
HILINE.say("If you enter a path you don't like, you will have manually remove it if you confirm it.")
HILINE.say("<% Paint['Good', 'green', :bold] %>: path/to/dir ‖ <% Paint['Bad', :red, :bold] %>: /root/paths/are/bad/mmkay")
folder = HILINE.ask('? ') do |q|
q.confirm = true
q.default = '.'
q.validate = /^[^\/].*$/
end
folder = Pathname("#{file_folder}/#{folder}")
begin
FileUtils.mkdir_p(File.join(Mkmatter::Methods.get_jekyll_root, folder))
rescue Errno::EEXIST
HILINE.say("<% Paint['Error', 'red', :bold] %>:Insufficient Permissions")
exit 1
end
path = Pathname(folder).realdirpath.join(filename)
end
File.open(path.to_path, 'a') do |fd|
answers.to_h = {:layout => 'post'}
fd.puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
fd.puts '---'
end
Mkmatter::Methods.launch_editor(options[:editor], path)
else
puts "Not in a Jekyll directory. (no '_config.yml' in any parent directory)"
exit 1
end
elsif options[:draft].nil? and options[:file].nil?
@questions = Mkmatter::Questions::Post.new(HILINE).ask
answers = Mkmatter::Answers.new(@questions, options[:publish])
puts ''
puts answers.to_h.stringify_keys.to_yaml(indentation: 2)
puts '---'
end
end
|