bridgetown-core 0.14.0 → 0.15.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +3 -1
- data/bin/bridgetown +9 -23
- data/bridgetown-core.gemspec +3 -1
- data/lib/bridgetown-core.rb +9 -2
- data/lib/bridgetown-core/commands/apply.rb +73 -0
- data/lib/bridgetown-core/commands/base.rb +45 -0
- data/lib/bridgetown-core/commands/build.rb +91 -86
- data/lib/bridgetown-core/commands/clean.rb +30 -29
- data/lib/bridgetown-core/commands/concerns/actions.rb +128 -0
- data/lib/bridgetown-core/commands/concerns/build_options.rb +76 -0
- data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +18 -0
- data/lib/bridgetown-core/commands/concerns/summarizable.rb +13 -0
- data/lib/bridgetown-core/commands/console.rb +57 -39
- data/lib/bridgetown-core/commands/doctor.rb +126 -126
- data/lib/bridgetown-core/commands/new.rb +120 -155
- data/lib/bridgetown-core/commands/plugins.rb +167 -130
- data/lib/bridgetown-core/commands/registrations.rb +16 -0
- data/lib/bridgetown-core/commands/serve.rb +219 -215
- data/lib/bridgetown-core/concerns/convertible.rb +1 -4
- data/lib/bridgetown-core/concerns/site/renderable.rb +1 -2
- data/lib/bridgetown-core/drops/document_drop.rb +9 -1
- data/lib/bridgetown-core/drops/page_drop.rb +1 -1
- data/lib/bridgetown-core/excerpt.rb +4 -1
- data/lib/bridgetown-core/generators/prototype_generator.rb +2 -0
- data/lib/bridgetown-core/liquid_renderer.rb +1 -0
- data/lib/bridgetown-core/liquid_renderer/file.rb +1 -4
- data/lib/bridgetown-core/liquid_renderer/file_system.rb +3 -1
- data/lib/bridgetown-core/page.rb +3 -18
- data/lib/bridgetown-core/plugin_manager.rb +31 -13
- data/lib/bridgetown-core/renderer.rb +31 -18
- data/lib/bridgetown-core/tags/include.rb +14 -0
- data/lib/bridgetown-core/tags/render_content.rb +39 -16
- data/lib/bridgetown-core/tags/with.rb +15 -0
- data/lib/bridgetown-core/utils.rb +44 -0
- data/lib/bridgetown-core/version.rb +2 -2
- data/lib/bridgetown-core/watcher.rb +17 -10
- data/lib/site_template/Gemfile.erb +19 -0
- data/lib/site_template/bridgetown.config.yml +5 -3
- data/lib/site_template/package.json +1 -0
- data/lib/site_template/src/_components/footer.liquid +3 -0
- data/lib/site_template/src/_components/head.liquid +9 -0
- data/lib/site_template/src/{_includes/navbar.html → _components/navbar.liquid} +0 -0
- data/lib/site_template/src/_layouts/default.html +3 -3
- data/lib/site_template/start.js +1 -1
- data/lib/site_template/webpack.config.js +3 -3
- metadata +53 -19
- data/lib/bridgetown-core/command.rb +0 -112
- data/lib/bridgetown-core/commands/help.rb +0 -34
- data/lib/site_template/src/_components/.keep +0 -0
- data/lib/site_template/src/_includes/footer.html +0 -3
- data/lib/site_template/src/_includes/head.html +0 -9
@@ -1,187 +1,152 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "erb"
|
4
|
-
|
5
3
|
module Bridgetown
|
6
4
|
module Commands
|
7
|
-
class New <
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def init_with_program(prog)
|
12
|
-
prog.command(:new) do |c|
|
13
|
-
c.syntax "new PATH"
|
14
|
-
c.description "Creates a new Bridgetown site scaffold in PATH"
|
15
|
-
|
16
|
-
c.option "force", "--force", "Force creation even if PATH already exists"
|
17
|
-
c.option "skip-bundle", "--skip-bundle", "Skip 'bundle install'"
|
18
|
-
c.option "skip-yarn", "--skip-yarn", "Skip 'yarn install'"
|
19
|
-
|
20
|
-
c.action do |args, options|
|
21
|
-
Bridgetown::Commands::New.process(args, options)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def process(args, options = {})
|
27
|
-
raise ArgumentError, "You must specify a path." if args.empty?
|
28
|
-
|
29
|
-
new_site_path = File.expand_path(args.join(" "), Dir.pwd)
|
30
|
-
FileUtils.mkdir_p new_site_path
|
31
|
-
if preserve_source_location?(new_site_path, options)
|
32
|
-
Bridgetown.logger.error "Conflict:", "#{new_site_path} exists and is not empty."
|
33
|
-
Bridgetown.logger.abort_with "", "Ensure #{new_site_path} is empty or else " \
|
34
|
-
"try again with `--force` to proceed and overwrite any files."
|
35
|
-
end
|
36
|
-
|
37
|
-
Bridgetown.logger.info("Creating:".green, new_site_path)
|
5
|
+
class New < Thor::Group
|
6
|
+
include Thor::Actions
|
7
|
+
extend Summarizable
|
38
8
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
def scaffold_post_content
|
45
|
-
ERB.new(File.read(File.expand_path(scaffold_path, site_template))).result
|
46
|
-
end
|
47
|
-
|
48
|
-
# Internal: Gets the filename of the sample post to be created
|
49
|
-
#
|
50
|
-
# Returns the filename of the sample post, as a String
|
51
|
-
def initialized_post_name
|
52
|
-
"src/_posts/#{Time.now.strftime("%Y-%m-%d")}-welcome-to-bridgetown.md"
|
53
|
-
end
|
9
|
+
Registrations.register do
|
10
|
+
register(New, "new", "new PATH", New.summary)
|
11
|
+
end
|
54
12
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
13
|
+
def self.banner
|
14
|
+
"bridgetown new PATH"
|
15
|
+
end
|
16
|
+
summary "Creates a new Bridgetown site scaffold in PATH"
|
17
|
+
|
18
|
+
class_option :apply,
|
19
|
+
aliases: "-a",
|
20
|
+
banner: "PATH|URL",
|
21
|
+
desc: "Apply an automation after creating the site scaffold"
|
22
|
+
class_option :force,
|
23
|
+
type: :boolean,
|
24
|
+
desc: "Force creation even if PATH already exists"
|
25
|
+
class_option :"skip-bundle",
|
26
|
+
type: :boolean,
|
27
|
+
desc: "Skip 'bundle install'"
|
28
|
+
class_option :"skip-yarn",
|
29
|
+
type: :boolean,
|
30
|
+
desc: "Skip 'yarn install'"
|
31
|
+
|
32
|
+
DOCSURL = "https://bridgetownrb.com/docs"
|
33
|
+
|
34
|
+
def self.exit_on_failure?
|
35
|
+
false
|
36
|
+
end
|
79
37
|
|
80
|
-
|
81
|
-
|
38
|
+
def self.source_root
|
39
|
+
File.expand_path("../../site_template", __dir__)
|
40
|
+
end
|
82
41
|
|
83
|
-
|
84
|
-
|
85
|
-
|
42
|
+
class << self
|
43
|
+
attr_accessor :created_site_dir
|
44
|
+
end
|
86
45
|
|
87
|
-
|
88
|
-
|
89
|
-
end
|
90
|
-
end
|
46
|
+
def new_site
|
47
|
+
raise ArgumentError, "You must specify a path." if args.empty?
|
91
48
|
|
92
|
-
|
93
|
-
|
49
|
+
new_site_path = File.expand_path(args.join(" "), Dir.pwd)
|
50
|
+
if preserve_source_location?(new_site_path, options)
|
51
|
+
say_status :conflict, "#{new_site_path} exists and is not empty.", :red
|
52
|
+
Bridgetown.logger.abort_with "Ensure #{new_site_path} is empty or else " \
|
53
|
+
"try again with `--force` to proceed and overwrite any files."
|
94
54
|
end
|
95
55
|
|
96
|
-
|
97
|
-
FileUtils.cp_r site_template + "/.", path
|
98
|
-
FileUtils.chmod_R "u+w", path
|
99
|
-
FileUtils.rm File.expand_path(scaffold_path, path)
|
100
|
-
end
|
56
|
+
self.destination_root = self.class.created_site_dir = new_site_path
|
101
57
|
|
102
|
-
|
103
|
-
|
104
|
-
|
58
|
+
say_status :create, new_site_path
|
59
|
+
create_site new_site_path
|
60
|
+
after_install new_site_path, args.join(" "), options
|
61
|
+
end
|
105
62
|
|
106
|
-
|
107
|
-
"src/_posts/0000-00-00-welcome-to-bridgetown.md.erb"
|
108
|
-
end
|
63
|
+
protected
|
109
64
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength #
|
114
|
-
def after_install(path, cli_path, options = {})
|
115
|
-
logger = Bridgetown.logger
|
116
|
-
git_init path
|
117
|
-
|
118
|
-
unless options["skip-bundle"]
|
119
|
-
begin
|
120
|
-
require "bundler"
|
121
|
-
bundle_install path
|
122
|
-
rescue LoadError
|
123
|
-
logger.info "Could not load Bundler. Bundle install skipped."
|
124
|
-
end
|
125
|
-
end
|
65
|
+
def preserve_source_location?(path, options)
|
66
|
+
!options["force"] && Dir.exist?(path)
|
67
|
+
end
|
126
68
|
|
127
|
-
|
69
|
+
def create_site(new_site_path)
|
70
|
+
directory ".", ".", exclude_pattern: %r!\.erb|DS_Store$!
|
71
|
+
FileUtils.chmod_R "u+w", new_site_path
|
128
72
|
|
129
|
-
|
73
|
+
template(
|
74
|
+
"src/_posts/0000-00-00-welcome-to-bridgetown.md.erb",
|
75
|
+
"src/_posts/#{Time.now.strftime("%Y-%m-%d")}-welcome-to-bridgetown.md"
|
76
|
+
)
|
77
|
+
template("Gemfile.erb", "Gemfile")
|
78
|
+
end
|
130
79
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
80
|
+
# After a new site has been created, print a success notification and
|
81
|
+
# then automatically execute bundle install from within the new site dir
|
82
|
+
# unless the user opts to skip 'bundle install'.
|
83
|
+
# rubocop:todo Metrics/CyclomaticComplexity
|
84
|
+
def after_install(path, cli_path, options = {})
|
85
|
+
git_init path
|
86
|
+
|
87
|
+
@skipped_bundle = true # is set to false if bundle install worked
|
88
|
+
bundle_install path unless options["skip-bundle"]
|
89
|
+
|
90
|
+
@skipped_yarn = true
|
91
|
+
yarn_install path unless options["skip-yarn"]
|
92
|
+
|
93
|
+
invoke(Apply, [], options) if options[:apply]
|
94
|
+
|
95
|
+
logger = Bridgetown.logger
|
96
|
+
yarn_start = "yarn start"
|
97
|
+
logger.info ""
|
98
|
+
logger.info "Success!".green, "🎉 Your new Bridgetown site was" \
|
99
|
+
" generated in #{cli_path.cyan}."
|
100
|
+
if options["skip-yarn"]
|
101
|
+
logger.info "You can now #{"cd".cyan} #{cli_path.cyan} to get started."
|
102
|
+
logger.info "You'll probably also want to #{"yarn install".cyan}" \
|
103
|
+
" to load in your frontend assets."
|
104
|
+
else
|
105
|
+
logger.info "You can now #{"cd".cyan} and run #{yarn_start.cyan} to get started."
|
143
106
|
end
|
144
|
-
|
107
|
+
logger.info "Then check out our online documentation for" \
|
108
|
+
" next steps: #{DOCSURL.cyan}"
|
145
109
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
110
|
+
logger.info "Bundle install skipped.".yellow if @skipped_bundle
|
111
|
+
logger.info "Yarn install skipped.".yellow if @skipped_yarn
|
112
|
+
end
|
113
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
114
|
+
|
115
|
+
def bundle_install(path)
|
116
|
+
unless Bridgetown.environment == "test"
|
117
|
+
require "bundler"
|
118
|
+
Bundler.with_clean_env do
|
119
|
+
inside(path) do
|
120
|
+
run "bundle install", abort_on_failure: true
|
154
121
|
end
|
155
|
-
|
156
|
-
raise SystemExit unless process.success?
|
157
122
|
end
|
158
123
|
end
|
124
|
+
@skipped_bundle = false
|
125
|
+
rescue LoadError
|
126
|
+
say_status :run, "Could not load Bundler. Bundle install skipped.", :red
|
127
|
+
rescue SystemExit
|
128
|
+
say_status :run, "Problem occured while running bundle install.", :red
|
129
|
+
end
|
159
130
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
Bridgetown.logger.info("Git:".green, line.strip) unless line.to_s.empty?
|
165
|
-
end
|
131
|
+
def git_init(path)
|
132
|
+
unless Bridgetown.environment == "test"
|
133
|
+
inside(path) do
|
134
|
+
run "git init", abort_on_failure: true
|
166
135
|
end
|
167
|
-
rescue SystemCallError
|
168
136
|
end
|
137
|
+
rescue SystemExit
|
138
|
+
say_status :run, "Could not load git. git init skipped.", :red
|
139
|
+
end
|
169
140
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
output.to_s.each_line do |line|
|
175
|
-
next if line.to_s.empty? ||
|
176
|
-
line.strip.start_with?("warning ") ||
|
177
|
-
line.include?("No lockfile found")
|
178
|
-
|
179
|
-
Bridgetown.logger.info("Yarn:".green, line.strip)
|
180
|
-
end
|
141
|
+
def yarn_install(path)
|
142
|
+
unless Bridgetown.environment == "test"
|
143
|
+
inside(path) do
|
144
|
+
run "yarn install", abort_on_failure: true
|
181
145
|
end
|
182
|
-
rescue SystemCallError
|
183
|
-
Bridgetown.logger.info "Could not load yarn. yarn install skipped."
|
184
146
|
end
|
147
|
+
@skipped_yarn = false
|
148
|
+
rescue SystemExit
|
149
|
+
say_status :run, "Could not load yarn. yarn install skipped.", :red
|
185
150
|
end
|
186
151
|
end
|
187
152
|
end
|
@@ -2,166 +2,203 @@
|
|
2
2
|
|
3
3
|
module Bridgetown
|
4
4
|
module Commands
|
5
|
-
class Plugins <
|
6
|
-
|
7
|
-
|
8
|
-
plugins_cmd = prog.command(:plugins) do |c|
|
9
|
-
c.syntax "plugins <subcommand>"
|
10
|
-
c.description "List installed plugins or access plugin content"
|
11
|
-
|
12
|
-
c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array,
|
13
|
-
"Custom configuration file"
|
14
|
-
|
15
|
-
c.action do
|
16
|
-
output_supercommand_syntax(c)
|
17
|
-
end
|
18
|
-
end
|
5
|
+
class Plugins < Thor
|
6
|
+
include Thor::Actions
|
7
|
+
include ConfigurationOverridable
|
19
8
|
|
20
|
-
|
21
|
-
|
22
|
-
|
9
|
+
Registrations.register do
|
10
|
+
desc "plugins <command>", "List installed plugins or access plugin content"
|
11
|
+
subcommand "plugins", Plugins
|
12
|
+
end
|
23
13
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
14
|
+
desc "list", "List information about installed plugins"
|
15
|
+
def list
|
16
|
+
site = Bridgetown::Site.new(configuration_with_overrides(options))
|
17
|
+
site.reset
|
18
|
+
Bridgetown::Hooks.trigger :site, :pre_read, site
|
28
19
|
|
29
|
-
|
30
|
-
subcmd.syntax "cd <origin/dir>"
|
31
|
-
subcmd.description "Open directory (content, layouts, etc.) within the plugin origin"
|
20
|
+
pm = site.plugin_manager
|
32
21
|
|
33
|
-
|
34
|
-
|
35
|
-
puts subcmd.to_s
|
36
|
-
else
|
37
|
-
cd(args, options)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
22
|
+
plugins_list = pm.class.registered_plugins.reject do |plugin|
|
23
|
+
plugin.to_s.end_with? "site_builder.rb"
|
41
24
|
end
|
42
25
|
|
43
|
-
|
44
|
-
|
26
|
+
Bridgetown.logger.info("Registered Plugins:", plugins_list.length.to_s.yellow.bold)
|
27
|
+
|
28
|
+
plugins_list.each do |plugin|
|
29
|
+
unless plugin.to_s.end_with? "site_builder.rb"
|
30
|
+
Bridgetown.logger.info("", plugin.to_s.sub(site.in_root_dir("/"), ""))
|
31
|
+
end
|
45
32
|
end
|
46
33
|
|
47
|
-
|
48
|
-
site = Bridgetown::Site.new(configuration_from_options(options))
|
49
|
-
site.reset
|
50
|
-
Bridgetown::Hooks.trigger :site, :pre_read, site
|
34
|
+
Bridgetown.logger.info("Source Manifests:", "---") unless pm.class.source_manifests.empty?
|
51
35
|
|
52
|
-
|
36
|
+
pm.class.source_manifests.each do |manifest|
|
37
|
+
Bridgetown.logger.info("Origin:", (manifest.origin || "n/a").to_s.green)
|
38
|
+
Bridgetown.logger.info("Components:", (manifest.components || "n/a").to_s.cyan)
|
39
|
+
Bridgetown.logger.info("Content:", (manifest.content || "n/a").to_s.cyan)
|
40
|
+
Bridgetown.logger.info("Layouts:", (manifest.layouts || "n/a").to_s.cyan)
|
53
41
|
|
54
|
-
|
55
|
-
|
56
|
-
end
|
42
|
+
Bridgetown.logger.info("", "---")
|
43
|
+
end
|
57
44
|
|
58
|
-
|
45
|
+
unless Bridgetown.autoload? :Builder
|
46
|
+
builders = Bridgetown::Builder.descendants
|
47
|
+
Bridgetown.logger.info("Builders:", builders.length.to_s.yellow.bold)
|
59
48
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
49
|
+
builders.each do |builder|
|
50
|
+
name = builder.respond_to?(:custom_name) ? builder.custom_name : builder.name
|
51
|
+
name_components = name.split("::")
|
52
|
+
last_name = name_components.pop
|
53
|
+
name_components.push last_name.magenta
|
54
|
+
Bridgetown.logger.info("", name_components.join("::"))
|
64
55
|
end
|
56
|
+
end
|
65
57
|
|
66
|
-
|
58
|
+
Bridgetown.logger.info("Converters:", site.converters.length.to_s.yellow.bold)
|
67
59
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
60
|
+
site.converters.each do |converter|
|
61
|
+
name = plugin_name_for(converter)
|
62
|
+
name_components = name.split("::")
|
63
|
+
last_name = name_components.pop
|
64
|
+
name_components.push last_name.magenta
|
65
|
+
Bridgetown.logger.info("", name_components.join("::"))
|
66
|
+
end
|
73
67
|
|
74
|
-
|
75
|
-
end
|
68
|
+
Bridgetown.logger.info("Generators:", site.generators.length.to_s.yellow.bold)
|
76
69
|
|
77
|
-
|
78
|
-
|
79
|
-
|
70
|
+
site.generators.each do |generator|
|
71
|
+
name = plugin_name_for(generator)
|
72
|
+
name_components = name.split("::")
|
73
|
+
last_name = name_components.pop
|
74
|
+
name_components.push last_name.magenta
|
75
|
+
Bridgetown.logger.info("", name_components.join("::"))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
long_desc <<-DOC
|
80
|
+
Open a directory (content, layouts, etc.) within the plugin origin. \n
|
81
|
+
First run bridgetown plugins list to view source manifests currently
|
82
|
+
set up on your site.\n
|
83
|
+
Then look for the origin of the manifest and the folder you'd like to
|
84
|
+
open.\n
|
85
|
+
So for example, with an origin of SamplePlugin and a folder of
|
86
|
+
Layouts, you'd run:\n
|
87
|
+
bridgetown plugins cd SamplePlugin/Layouts
|
88
|
+
DOC
|
89
|
+
desc "cd <origin/dir>", "Open folder (content, layouts, etc.) within the plugin origin"
|
90
|
+
|
91
|
+
# This is super useful if you want to copy files out of plugins to override.
|
92
|
+
#
|
93
|
+
# Example:
|
94
|
+
# bridgetown plugins cd AwesomePlugin/layouts
|
95
|
+
# cp -r * $BRIDGETOWN_SITE/src/_layouts
|
96
|
+
#
|
97
|
+
# Now all the plugin's layouts will be in the site repo directly.
|
98
|
+
#
|
99
|
+
def cd(arg)
|
100
|
+
site = Bridgetown::Site.new(configuration_with_overrides(options))
|
101
|
+
|
102
|
+
pm = site.plugin_manager
|
103
|
+
|
104
|
+
directive = arg.split("/")
|
105
|
+
unless directive[1]
|
106
|
+
Bridgetown.logger.warn("Oops!", "Your command needs to be in the <origin/dir> format")
|
107
|
+
return
|
108
|
+
end
|
109
|
+
|
110
|
+
manifest = pm.class.source_manifests.find do |source_manifest|
|
111
|
+
source_manifest.origin.to_s == directive[0]
|
112
|
+
end
|
80
113
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
114
|
+
if manifest&.respond_to?(directive[1].downcase)
|
115
|
+
dir = manifest.send(directive[1].downcase)
|
116
|
+
Bridgetown.logger.info("Opening the #{dir.green} folder for" \
|
117
|
+
" #{manifest.origin.to_s.cyan}…")
|
118
|
+
Bridgetown.logger.info("Type #{"exit".yellow} when you're done to" \
|
119
|
+
" return to your site root.")
|
120
|
+
puts
|
121
|
+
|
122
|
+
Dir.chdir dir do
|
123
|
+
ENV["BRIDGETOWN_SITE"] = site.root_dir
|
124
|
+
if ENV["SHELL"]
|
125
|
+
system(ENV["SHELL"])
|
126
|
+
else
|
127
|
+
system("/bin/sh")
|
87
128
|
end
|
88
129
|
end
|
89
130
|
|
90
|
-
|
131
|
+
puts
|
132
|
+
Bridgetown.logger.info("Done!", "You're back in #{Dir.pwd.green}")
|
133
|
+
else
|
134
|
+
Bridgetown.logger.warn("Oops!", "I wasn't able to find the" \
|
135
|
+
" #{directive[1]} folder for #{directive[0]}")
|
136
|
+
end
|
137
|
+
end
|
91
138
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
139
|
+
desc "new NAME", "Create a new plugin NAME (please-use-dashes) by" \
|
140
|
+
" cloning the sample plugin repo"
|
141
|
+
# rubocop:disable Layout/LineLength
|
142
|
+
def new(plugin_name)
|
143
|
+
folder_name = plugin_name.underscore
|
144
|
+
name = folder_name.dasherize
|
145
|
+
module_name = folder_name.camelize
|
99
146
|
|
100
|
-
|
147
|
+
run "git clone https://github.com/bridgetownrb/bridgetown-sample-plugin #{name}"
|
148
|
+
new_gemspec = "#{name}.gemspec"
|
101
149
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
last_name = name_components.pop
|
106
|
-
name_components.push last_name.magenta
|
107
|
-
Bridgetown.logger.info("", name_components.join("::"))
|
108
|
-
end
|
109
|
-
end
|
150
|
+
inside name do # rubocop:todo Metrics/BlockLength
|
151
|
+
run "rm -rf .git"
|
152
|
+
run "git init"
|
110
153
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
#
|
117
|
-
# Now all the plugin's layouts will be in the site repo directly.
|
118
|
-
#
|
119
|
-
def cd(args, options)
|
120
|
-
site = Bridgetown::Site.new(configuration_from_options(options))
|
121
|
-
|
122
|
-
pm = site.plugin_manager
|
123
|
-
|
124
|
-
directive = args[0].split("/")
|
125
|
-
unless directive[1]
|
126
|
-
Bridgetown.logger.warn("Oops!", "Your command needs to be in the <origin/dir> format")
|
127
|
-
return
|
128
|
-
end
|
154
|
+
run "mv bridgetown-sample-plugin.gemspec #{new_gemspec}"
|
155
|
+
gsub_file new_gemspec, "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
|
156
|
+
gsub_file new_gemspec, "bridgetown-sample-plugin", name
|
157
|
+
gsub_file new_gemspec, "sample-plugin", name
|
158
|
+
gsub_file new_gemspec, "SamplePlugin", module_name
|
129
159
|
|
130
|
-
|
131
|
-
|
132
|
-
end
|
160
|
+
gsub_file "package.json", "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
|
161
|
+
gsub_file "package.json", "bridgetown-sample-plugin", name
|
133
162
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
" #{manifest.origin.to_s.cyan}…")
|
138
|
-
Bridgetown.logger.info("Type #{"exit".yellow} when you're done to" \
|
139
|
-
" return to your site root.")
|
140
|
-
puts
|
141
|
-
|
142
|
-
Dir.chdir dir do
|
143
|
-
ENV["BRIDGETOWN_SITE"] = site.root_dir
|
144
|
-
if ENV["SHELL"]
|
145
|
-
system(ENV["SHELL"])
|
146
|
-
else
|
147
|
-
system("/bin/sh")
|
148
|
-
end
|
149
|
-
end
|
163
|
+
run "mv lib/sample-plugin.rb lib/#{name}.rb"
|
164
|
+
gsub_file "lib/#{name}.rb", "sample-plugin", name
|
165
|
+
gsub_file "lib/#{name}.rb", "SamplePlugin", module_name
|
150
166
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
167
|
+
run "mv lib/sample-plugin lib/#{name}"
|
168
|
+
gsub_file "lib/#{name}/builder.rb", "SamplePlugin", module_name
|
169
|
+
gsub_file "lib/#{name}/version.rb", "SamplePlugin", module_name
|
170
|
+
|
171
|
+
run "mv spec/sample-plugin_spec.rb spec/#{name}_spec.rb"
|
172
|
+
gsub_file "spec/#{name}_spec.rb", "SamplePlugin", module_name
|
173
|
+
gsub_file "spec/spec_helper.rb", "sample-plugin", name
|
174
|
+
|
175
|
+
run "mv components/sample_plugin components/#{folder_name}"
|
176
|
+
run "mv content/sample_plugin content/#{folder_name}"
|
177
|
+
run "mv layouts/sample_plugin layouts/#{folder_name}"
|
178
|
+
|
179
|
+
gsub_file "layouts/#{folder_name}/layout.html", "sample_plugin", folder_name
|
180
|
+
gsub_file "content/#{folder_name}/example_page.md", "sample_plugin", folder_name
|
181
|
+
gsub_file "components/#{folder_name}/layout_help.liquid", "sample_plugin", folder_name
|
182
|
+
|
183
|
+
gsub_file "frontend/javascript/index.js", "bridgetown-sample-plugin", name
|
184
|
+
gsub_file "frontend/javascript/index.js", "SamplePlugin", module_name
|
157
185
|
end
|
186
|
+
say ""
|
187
|
+
say_status "Done!", "Have fun writing your new #{name} plugin :)"
|
188
|
+
say_status "Remember:", "Don't forget to rename the SamplePlugin" \
|
189
|
+
" code identifiers and paths to your own" \
|
190
|
+
" indentifer, as well as update your README " \
|
191
|
+
" and CHANGELOG files as necessary."
|
192
|
+
end
|
193
|
+
# rubocop:enable Layout/LineLength
|
158
194
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
195
|
+
protected
|
196
|
+
|
197
|
+
def plugin_name_for(plugin)
|
198
|
+
if plugin.class.respond_to?(:custom_name)
|
199
|
+
plugin.class.custom_name
|
200
|
+
else
|
201
|
+
plugin.class.name
|
165
202
|
end
|
166
203
|
end
|
167
204
|
end
|