sutty-cli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +168 -0
- data/README.md +60 -0
- data/exe/sutty-cli +18 -0
- data/lib/sutty/cli.rb +8 -0
- data/lib/sutty/cli/cli.rb +163 -0
- data/lib/sutty/cli/command.rb +123 -0
- data/lib/sutty/cli/commands/container.rb +39 -0
- data/lib/sutty/cli/commands/field.rb +87 -0
- data/lib/sutty/cli/commands/layout.rb +57 -0
- data/lib/sutty/cli/commands/post.rb +69 -0
- data/lib/sutty/cli/commands/theme.rb +49 -0
- data/lib/sutty/cli/templates/field/array.yml.erb +14 -0
- data/lib/sutty/cli/templates/field/belongs_to.yml.erb +16 -0
- data/lib/sutty/cli/templates/field/boolean.yml.erb +11 -0
- data/lib/sutty/cli/templates/field/color.yml.erb +11 -0
- data/lib/sutty/cli/templates/field/content.yml.erb +14 -0
- data/lib/sutty/cli/templates/field/date.yml.erb +11 -0
- data/lib/sutty/cli/templates/field/email.yml.erb +14 -0
- data/lib/sutty/cli/templates/field/encrypted_text.yml.erb +11 -0
- data/lib/sutty/cli/templates/field/event.yml.erb +40 -0
- data/lib/sutty/cli/templates/field/file.yml.erb +19 -0
- data/lib/sutty/cli/templates/field/geo.yml.erb +17 -0
- data/lib/sutty/cli/templates/field/has_and_belongs_to_many.yml.erb +16 -0
- data/lib/sutty/cli/templates/field/has_many.yml.erb +16 -0
- data/lib/sutty/cli/templates/field/image.yml.erb +19 -0
- data/lib/sutty/cli/templates/field/locales.yml.erb +11 -0
- data/lib/sutty/cli/templates/field/markdown.yml.erb +14 -0
- data/lib/sutty/cli/templates/field/markdown_content.yml.erb +14 -0
- data/lib/sutty/cli/templates/field/number.yml.erb +11 -0
- data/lib/sutty/cli/templates/field/order.yml.erb +11 -0
- data/lib/sutty/cli/templates/field/predefined_array.yml.erb +18 -0
- data/lib/sutty/cli/templates/field/related_posts.yml.erb +15 -0
- data/lib/sutty/cli/templates/field/string.yml.erb +14 -0
- data/lib/sutty/cli/templates/field/tel.yml.erb +14 -0
- data/lib/sutty/cli/templates/field/text.yml.erb +14 -0
- data/lib/sutty/cli/templates/field/url.yml.erb +14 -0
- data/lib/sutty/cli/version.rb +5 -0
- metadata +179 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../command'
|
4
|
+
require 'tty-command'
|
5
|
+
|
6
|
+
module Sutty
|
7
|
+
module Cli
|
8
|
+
module Commands
|
9
|
+
class Container < Sutty::Cli::Command
|
10
|
+
attr_reader :name
|
11
|
+
|
12
|
+
def initialize(name, options)
|
13
|
+
@name = name
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute(input: $stdin, output: $stdout)
|
18
|
+
cmd.run('git clone https://0xacab.org/sutty/containers/skel.git', name)
|
19
|
+
|
20
|
+
Dir.chdir name do
|
21
|
+
cmd.run('git remote rename origin upstream')
|
22
|
+
cmd.run('git remote add origin', origin)
|
23
|
+
cmd.run('git push -u origin master')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def origin
|
30
|
+
@origin ||= 'git@0xacab.org:sutty/containers/' + name + '.git'
|
31
|
+
end
|
32
|
+
|
33
|
+
def cmd
|
34
|
+
@cmd ||= TTY::Command.new
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../command'
|
4
|
+
require 'tty-file'
|
5
|
+
require 'tty-logger'
|
6
|
+
require 'pry'
|
7
|
+
|
8
|
+
module Sutty
|
9
|
+
module Cli
|
10
|
+
module Commands
|
11
|
+
class Field < Sutty::Cli::Command
|
12
|
+
attr_reader :name, :options
|
13
|
+
|
14
|
+
INVERSE_REQUIRED = %w[has_many belongs_to has_and_belongs_to_many].freeze
|
15
|
+
VALUE_REQUIRED = %w[-F --filter].freeze
|
16
|
+
|
17
|
+
def initialize(name, options)
|
18
|
+
@name = name
|
19
|
+
@options = options
|
20
|
+
end
|
21
|
+
|
22
|
+
def execute(input: $stdin, output: $stdout)
|
23
|
+
unless data_layout_contents.scan(/\n#{name}:\n/).empty?
|
24
|
+
logger.info "The #{name} field is already present, please edit #{data_layout}"
|
25
|
+
return true
|
26
|
+
end
|
27
|
+
|
28
|
+
TTY::File.safe_append_to_file(data_layout) do
|
29
|
+
ERB.new(template_contents, trim_mode: '<>', eoutvar: '@output_buffer').result(context)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.fields
|
34
|
+
@@fields ||= Dir.glob(source_dir.to_s + '/*.yml.erb').map do |f|
|
35
|
+
File.basename f, '.yml.erb'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.inverse_required?
|
40
|
+
ARGV.any? { |f| INVERSE_REQUIRED.include? f }
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.value_required?
|
44
|
+
ARGV.any? { |f| VALUE_REQUIRED.include? f }
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def self.source_dir
|
50
|
+
@@source_dir ||= Pathname(__dir__).join('..', 'templates', 'field')
|
51
|
+
end
|
52
|
+
|
53
|
+
def source_dir
|
54
|
+
self.class.source_dir
|
55
|
+
end
|
56
|
+
|
57
|
+
def context
|
58
|
+
return @context if @context
|
59
|
+
@context = OpenStruct.new(**options.transform_keys(&:to_sym))
|
60
|
+
@context[:name] = name
|
61
|
+
|
62
|
+
@context = @context.instance_eval('binding')
|
63
|
+
end
|
64
|
+
|
65
|
+
def template
|
66
|
+
@template ||= source_dir.join(options[:type] + '.yml.erb')
|
67
|
+
end
|
68
|
+
|
69
|
+
def template_contents
|
70
|
+
@template_contents ||= File.binread template
|
71
|
+
end
|
72
|
+
|
73
|
+
def data_layout
|
74
|
+
@data_layout ||= File.join('_data', 'layouts', options[:layout] + '.yml')
|
75
|
+
end
|
76
|
+
|
77
|
+
def data_layout_contents
|
78
|
+
@data_layout_contents ||= File.binread data_layout
|
79
|
+
end
|
80
|
+
|
81
|
+
def logger
|
82
|
+
@logger ||= TTY::Logger.new
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../command'
|
4
|
+
require 'tty-file'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
module Sutty
|
8
|
+
module Cli
|
9
|
+
module Commands
|
10
|
+
class Layout < Sutty::Cli::Command
|
11
|
+
attr_reader :name
|
12
|
+
|
13
|
+
def initialize(name, options)
|
14
|
+
@name = name
|
15
|
+
@options = options
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute(input: $stdin, output: $stdout)
|
19
|
+
TTY::File.create_file data_layout, YAML.dump(data_default_fields)
|
20
|
+
TTY::File.create_file html_layout, "---\nlayout: default\n---\n\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.layouts
|
24
|
+
@@layouts ||= Dir.glob(File.join('_data', 'layouts') + '/*.yml').map do |d|
|
25
|
+
File.basename d, '.yml'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def data_default_fields
|
32
|
+
@data_default_fields ||= {
|
33
|
+
'title' => {
|
34
|
+
'type' => 'string',
|
35
|
+
'label' => {
|
36
|
+
'es' => 'Título',
|
37
|
+
'en' => 'Title'
|
38
|
+
},
|
39
|
+
'help' => {
|
40
|
+
'es' => '',
|
41
|
+
'en' => ''
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def data_layout
|
48
|
+
@data_layout ||= File.join('_data', 'layouts', name + '.yml')
|
49
|
+
end
|
50
|
+
|
51
|
+
def html_layout
|
52
|
+
@html_layout ||= File.join('_layouts', name + '.html')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../command'
|
4
|
+
require 'tty-logger'
|
5
|
+
require 'tty-file'
|
6
|
+
require 'yaml'
|
7
|
+
require 'securerandom'
|
8
|
+
require 'jekyll/utils'
|
9
|
+
|
10
|
+
module Sutty
|
11
|
+
module Cli
|
12
|
+
module Commands
|
13
|
+
class Post < Sutty::Cli::Command
|
14
|
+
attr_reader :options
|
15
|
+
|
16
|
+
CONTENT_FIELDS = %w[content markdown_content].freeze
|
17
|
+
|
18
|
+
def initialize(options)
|
19
|
+
@options = options
|
20
|
+
end
|
21
|
+
|
22
|
+
def execute(input: $stdin, output: $stdout)
|
23
|
+
if File.exist? path
|
24
|
+
logger.info "The file #{path} already exists"
|
25
|
+
return true
|
26
|
+
end
|
27
|
+
|
28
|
+
TTY::File.create_file path, YAML.dump(data) + "---\n\n"
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def data
|
34
|
+
return @data if @data
|
35
|
+
|
36
|
+
@data = Hash[(data_layout.keys - CONTENT_FIELDS).map { |k| [k, nil] }]
|
37
|
+
|
38
|
+
# Required fields
|
39
|
+
@data['title'] = options[:title]
|
40
|
+
@data['layout'] = options[:layout]
|
41
|
+
@data['uuid'] = SecureRandom.uuid
|
42
|
+
@data['liquid'] = false
|
43
|
+
|
44
|
+
@data
|
45
|
+
end
|
46
|
+
|
47
|
+
def data_layout
|
48
|
+
@data_layout ||= YAML.safe_load(File.read(File.join('_data', 'layouts', options[:layout] + '.yml')))
|
49
|
+
end
|
50
|
+
|
51
|
+
def slug
|
52
|
+
@slug ||= Jekyll::Utils.slugify(options[:title])
|
53
|
+
end
|
54
|
+
|
55
|
+
def dir
|
56
|
+
@dir ||= '_' + options[:locale]
|
57
|
+
end
|
58
|
+
|
59
|
+
def path
|
60
|
+
@path ||= File.join(dir, options[:date] + '-' + slug + '.markdown')
|
61
|
+
end
|
62
|
+
|
63
|
+
def logger
|
64
|
+
@logger ||= TTY::Logger.new
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../command'
|
4
|
+
require 'tty-command'
|
5
|
+
|
6
|
+
module Sutty
|
7
|
+
module Cli
|
8
|
+
module Commands
|
9
|
+
class Theme < Sutty::Cli::Command
|
10
|
+
attr_reader :name
|
11
|
+
|
12
|
+
def initialize(name, options)
|
13
|
+
@name = name
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute(input: $stdin, output: $stdout)
|
18
|
+
cmd.run('git clone https://0xacab.org/sutty/jekyll/sutty-base-jekyll-theme.git', theme_name)
|
19
|
+
|
20
|
+
Dir.chdir theme_name do
|
21
|
+
cmd.run('git remote rename origin upstream')
|
22
|
+
cmd.run('git remote add origin', origin)
|
23
|
+
cmd.run('bundle install')
|
24
|
+
cmd.run('yarn install')
|
25
|
+
cmd.run('git mv sutty-base-jekyll-theme.gemspec', gemspec)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def theme_name
|
32
|
+
@theme_name ||= name + '-jekyll-theme'
|
33
|
+
end
|
34
|
+
|
35
|
+
def origin
|
36
|
+
@origin ||= 'git@0xacab.org:sutty/jekyll/' + theme_name + '.git'
|
37
|
+
end
|
38
|
+
|
39
|
+
def gemspec
|
40
|
+
@gemspec ||= theme_name + '.gemspec'
|
41
|
+
end
|
42
|
+
|
43
|
+
def cmd
|
44
|
+
@cmd ||= TTY::Command.new
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%= name %>:
|
2
|
+
type: 'belongs_to'
|
3
|
+
<% if required %>
|
4
|
+
required: true
|
5
|
+
<% end %>
|
6
|
+
inverse: '<%= inverse %>'
|
7
|
+
<% if filter %>
|
8
|
+
filter:
|
9
|
+
<%= filter %>: <%= value %>
|
10
|
+
<% end %>
|
11
|
+
label:
|
12
|
+
es: 'Nombre'
|
13
|
+
en: 'Name'
|
14
|
+
help:
|
15
|
+
es: 'Ayuda'
|
16
|
+
en: 'Ayuda'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<%= name %>:
|
2
|
+
type: 'event'
|
3
|
+
<% if required %>
|
4
|
+
required: true
|
5
|
+
<% end %>
|
6
|
+
zone:
|
7
|
+
label:
|
8
|
+
es: 'Zona horaria'
|
9
|
+
en: 'Time zone'
|
10
|
+
help:
|
11
|
+
es: 'Ayuda'
|
12
|
+
en: 'Ayuda'
|
13
|
+
date:
|
14
|
+
label:
|
15
|
+
es: 'Fecha'
|
16
|
+
en: 'Date'
|
17
|
+
help:
|
18
|
+
es: 'Ayuda'
|
19
|
+
en: 'Ayuda'
|
20
|
+
time:
|
21
|
+
label:
|
22
|
+
es: 'Horario'
|
23
|
+
en: 'Time'
|
24
|
+
help:
|
25
|
+
es: 'Ayuda'
|
26
|
+
en: 'Ayuda'
|
27
|
+
dtstart:
|
28
|
+
label:
|
29
|
+
es: 'Comienzo del evento'
|
30
|
+
en: 'Event start'
|
31
|
+
help:
|
32
|
+
es: 'Ayuda'
|
33
|
+
en: 'Ayuda'
|
34
|
+
dtend:
|
35
|
+
label:
|
36
|
+
es: 'Fin del evento'
|
37
|
+
en: 'Event end'
|
38
|
+
help:
|
39
|
+
es: 'Ayuda'
|
40
|
+
en: 'Ayuda'
|