bridgetown-core 0.13.0 → 0.15.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -1
  3. data/bin/bridgetown +9 -48
  4. data/bridgetown-core.gemspec +6 -2
  5. data/lib/bridgetown-core.rb +13 -3
  6. data/lib/bridgetown-core/cleaner.rb +1 -0
  7. data/lib/bridgetown-core/commands/apply.rb +73 -0
  8. data/lib/bridgetown-core/commands/base.rb +45 -0
  9. data/lib/bridgetown-core/commands/build.rb +91 -86
  10. data/lib/bridgetown-core/commands/clean.rb +30 -29
  11. data/lib/bridgetown-core/commands/concerns/actions.rb +123 -0
  12. data/lib/bridgetown-core/commands/concerns/build_options.rb +76 -0
  13. data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +18 -0
  14. data/lib/bridgetown-core/commands/concerns/summarizable.rb +13 -0
  15. data/lib/bridgetown-core/commands/console.rb +46 -39
  16. data/lib/bridgetown-core/commands/doctor.rb +126 -127
  17. data/lib/bridgetown-core/commands/new.rb +120 -158
  18. data/lib/bridgetown-core/commands/plugins.rb +206 -0
  19. data/lib/bridgetown-core/commands/registrations.rb +16 -0
  20. data/lib/bridgetown-core/commands/serve.rb +214 -215
  21. data/lib/bridgetown-core/{convertible.rb → concerns/convertible.rb} +3 -6
  22. data/lib/bridgetown-core/concerns/site/configurable.rb +153 -0
  23. data/lib/bridgetown-core/concerns/site/content.rb +111 -0
  24. data/lib/bridgetown-core/concerns/site/extensible.rb +56 -0
  25. data/lib/bridgetown-core/concerns/site/processable.rb +74 -0
  26. data/lib/bridgetown-core/concerns/site/renderable.rb +49 -0
  27. data/lib/bridgetown-core/concerns/site/writable.rb +31 -0
  28. data/lib/bridgetown-core/configuration.rb +2 -9
  29. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +0 -3
  30. data/lib/bridgetown-core/document.rb +1 -1
  31. data/lib/bridgetown-core/drops/page_drop.rb +1 -1
  32. data/lib/bridgetown-core/drops/site_drop.rb +1 -1
  33. data/lib/bridgetown-core/excerpt.rb +4 -1
  34. data/lib/bridgetown-core/external.rb +17 -21
  35. data/lib/bridgetown-core/filters.rb +10 -0
  36. data/lib/bridgetown-core/generators/prototype_generator.rb +3 -1
  37. data/lib/bridgetown-core/hooks.rb +62 -62
  38. data/lib/bridgetown-core/layout.rb +10 -4
  39. data/lib/bridgetown-core/liquid_renderer.rb +1 -0
  40. data/lib/bridgetown-core/liquid_renderer/file.rb +1 -4
  41. data/lib/bridgetown-core/liquid_renderer/file_system.rb +3 -1
  42. data/lib/bridgetown-core/page.rb +11 -19
  43. data/lib/bridgetown-core/plugin.rb +2 -0
  44. data/lib/bridgetown-core/plugin_manager.rb +88 -21
  45. data/lib/bridgetown-core/reader.rb +5 -0
  46. data/lib/bridgetown-core/readers/data_reader.rb +5 -2
  47. data/lib/bridgetown-core/readers/layout_reader.rb +9 -2
  48. data/lib/bridgetown-core/readers/plugin_content_reader.rb +48 -0
  49. data/lib/bridgetown-core/renderer.rb +38 -28
  50. data/lib/bridgetown-core/site.rb +20 -463
  51. data/lib/bridgetown-core/tags/include.rb +12 -0
  52. data/lib/bridgetown-core/tags/render_content.rb +29 -16
  53. data/lib/bridgetown-core/tags/with.rb +15 -0
  54. data/lib/bridgetown-core/utils.rb +45 -27
  55. data/lib/bridgetown-core/utils/ruby_exec.rb +1 -4
  56. data/lib/bridgetown-core/version.rb +2 -2
  57. data/lib/bridgetown-core/watcher.rb +21 -10
  58. data/lib/site_template/Gemfile.erb +19 -0
  59. data/lib/site_template/package.json +1 -0
  60. data/lib/site_template/plugins/{.keep → builders/.keep} +0 -0
  61. data/lib/site_template/plugins/site_builder.rb +4 -0
  62. data/lib/site_template/src/_components/footer.html +3 -0
  63. data/lib/site_template/src/_components/head.html +9 -0
  64. data/lib/site_template/src/{_includes → _components}/navbar.html +1 -0
  65. data/lib/site_template/src/_layouts/default.html +3 -3
  66. data/lib/site_template/src/posts.md +15 -0
  67. data/lib/site_template/start.js +1 -1
  68. data/lib/site_template/webpack.config.js +3 -3
  69. metadata +90 -18
  70. data/lib/bridgetown-core/command.rb +0 -106
  71. data/lib/bridgetown-core/commands/help.rb +0 -34
  72. data/lib/site_template/src/_components/.keep +0 -0
  73. data/lib/site_template/src/_includes/footer.html +0 -3
  74. data/lib/site_template/src/_includes/head.html +0 -9
@@ -1,190 +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 < Command
8
- class << self
9
- DOCSURL = "https://bridgetownrb.com/docs"
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
- create_site new_site_path
40
-
41
- after_install(new_site_path, args.join(" "), options)
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
- private
56
-
57
- def gemfile_contents
58
- <<~RUBY
59
- source "https://rubygems.org"
60
- # Hello! This is where you manage which Bridgetown version is used to run.
61
- # When you want to use a different version, change it below, save the
62
- # file and run `bundle install`. Run Bridgetown with `bundle exec`, like so:
63
- #
64
- # bundle exec bridgetown serve
65
- #
66
- # This will help ensure the proper Bridgetown version is running.
67
- #
68
- # To install a plugin, simply run bundle add and specify the group
69
- # "bridgetown_plugins". For example:
70
- #
71
- # bundle add some-new-plugin -g bridgetown_plugins
72
- #
73
- # Happy Bridgetowning!
74
-
75
- # Pull in latest Liquid from Shopify with new Render tag
76
- gem 'liquid', "> 4.0.3", github: "jaredcwhite/liquid"
77
-
78
- gem "bridgetown", "~> #{Bridgetown::VERSION}"
79
-
80
- RUBY
81
- end
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
82
37
 
83
- def create_site(new_site_path)
84
- create_sample_files new_site_path
38
+ def self.source_root
39
+ File.expand_path("../../site_template", __dir__)
40
+ end
85
41
 
86
- File.open(File.expand_path(initialized_post_name, new_site_path), "w") do |f|
87
- f.write(scaffold_post_content)
88
- end
42
+ class << self
43
+ attr_accessor :created_site_dir
44
+ end
89
45
 
90
- File.open(File.expand_path("Gemfile", new_site_path), "w") do |f|
91
- f.write(gemfile_contents)
92
- end
93
- end
46
+ def new_site
47
+ raise ArgumentError, "You must specify a path." if args.empty?
94
48
 
95
- def preserve_source_location?(path, options)
96
- !options["force"] && !Dir["#{path}/**/*"].empty?
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."
97
54
  end
98
55
 
99
- def create_sample_files(path)
100
- FileUtils.cp_r site_template + "/.", path
101
- FileUtils.chmod_R "u+w", path
102
- FileUtils.rm File.expand_path(scaffold_path, path)
103
- end
56
+ self.destination_root = self.class.created_site_dir = new_site_path
104
57
 
105
- def site_template
106
- File.expand_path("../../site_template", __dir__)
107
- end
58
+ say_status :create, new_site_path
59
+ create_site new_site_path
60
+ after_install new_site_path, args.join(" "), options
61
+ end
108
62
 
109
- def scaffold_path
110
- "src/_posts/0000-00-00-welcome-to-bridgetown.md.erb"
111
- end
63
+ protected
112
64
 
113
- # After a new site has been created, print a success notification and
114
- # then automatically execute bundle install from within the new site dir
115
- # unless the user opts to skip 'bundle install'.
116
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength #
117
- def after_install(path, cli_path, options = {})
118
- logger = Bridgetown.logger
119
- git_init path
120
-
121
- unless options["skip-bundle"]
122
- begin
123
- require "bundler"
124
- bundle_install path
125
- rescue LoadError
126
- logger.info "Could not load Bundler. Bundle install skipped."
127
- end
128
- end
65
+ def preserve_source_location?(path, options)
66
+ !options["force"] && Dir.exist?(path)
67
+ end
129
68
 
130
- yarn_install path unless options["skip-yarn"]
69
+ def create_site(new_site_path)
70
+ directory ".", ".", exclude_pattern: %r!\.erb|DS_Store$!
71
+ FileUtils.chmod_R "u+w", new_site_path
131
72
 
132
- yarn_start = "yarn start"
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
133
79
 
134
- logger.info "Success!".green, "🎉 Your new Bridgetown site was" \
135
- " generated in #{cli_path.cyan}."
136
- if options["skip-yarn"]
137
- logger.info "You can now #{"cd".cyan} #{cli_path.cyan} to get started."
138
- logger.info "You'll probably also want to #{"yarn install".cyan}" \
139
- " to load in your frontend assets."
140
- else
141
- logger.info "You can now #{"cd".cyan} and run #{yarn_start.cyan} to get started."
142
- end
143
- logger.info "Then check out our online documentation for" \
144
- " next steps: #{DOCSURL.cyan}"
145
- logger.info "Bundle install skipped." if options["skip-bundle"]
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."
146
106
  end
147
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength #
107
+ logger.info "Then check out our online documentation for" \
108
+ " next steps: #{DOCSURL.cyan}"
148
109
 
149
- def bundle_install(path)
150
- Bridgetown.logger.info "Running bundle install in #{path.cyan}..."
151
- Dir.chdir(path) do
152
- exe = Gem.bin_path("bundler", "bundle")
153
- process, output = Bridgetown::Utils::Exec.run("ruby", exe, "install")
154
-
155
- output.to_s.each_line do |line|
156
- Bridgetown.logger.info("Bundler:".green, line.strip) unless line.to_s.empty?
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
157
121
  end
158
-
159
- raise SystemExit unless process.success?
160
122
  end
161
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
162
130
 
163
- def git_init(path)
164
- Dir.chdir(path) do
165
- _process, output = Bridgetown::Utils::Exec.run("git", "init")
166
- output.to_s.each_line do |line|
167
- Bridgetown.logger.info("Git:".green, line.strip) unless line.to_s.empty?
168
- end
131
+ def git_init(path)
132
+ unless Bridgetown.environment == "test"
133
+ inside(path) do
134
+ run "git init", abort_on_failure: true
169
135
  end
170
- rescue SystemCallError
171
136
  end
137
+ rescue SystemExit
138
+ say_status :run, "Could not load git. git init skipped.", :red
139
+ end
172
140
 
173
- def yarn_install(path)
174
- Bridgetown.logger.info "Running yarn install in #{path.cyan}..."
175
- Dir.chdir(path) do
176
- _process, output = Bridgetown::Utils::Exec.run("yarn", "install")
177
- output.to_s.each_line do |line|
178
- next if line.to_s.empty? ||
179
- line.strip.start_with?("warning ") ||
180
- line.include?("No lockfile found")
181
-
182
- Bridgetown.logger.info("Yarn:".green, line.strip)
183
- end
141
+ def yarn_install(path)
142
+ unless Bridgetown.environment == "test"
143
+ inside(path) do
144
+ run "yarn install", abort_on_failure: true
184
145
  end
185
- rescue SystemCallError
186
- Bridgetown.logger.info "Could not load yarn. yarn install skipped."
187
146
  end
147
+ @skipped_yarn = false
148
+ rescue SystemExit
149
+ say_status :run, "Could not load yarn. yarn install skipped.", :red
188
150
  end
189
151
  end
190
152
  end
@@ -0,0 +1,206 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Commands
5
+ class Plugins < Thor
6
+ include Thor::Actions
7
+ include ConfigurationOverridable
8
+
9
+ Registrations.register do
10
+ desc "plugins <command>", "List installed plugins or access plugin content"
11
+ subcommand "plugins", Plugins
12
+ end
13
+
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
19
+
20
+ pm = site.plugin_manager
21
+
22
+ plugins_list = pm.class.registered_plugins.reject do |plugin|
23
+ plugin.to_s.end_with? "site_builder.rb"
24
+ end
25
+
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
32
+ end
33
+
34
+ Bridgetown.logger.info("Source Manifests:", "---") unless pm.class.source_manifests.empty?
35
+
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)
41
+
42
+ Bridgetown.logger.info("", "---")
43
+ end
44
+
45
+ unless Bridgetown.autoload? :Builder
46
+ builders = Bridgetown::Builder.descendants
47
+ Bridgetown.logger.info("Builders:", builders.length.to_s.yellow.bold)
48
+
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("::"))
55
+ end
56
+ end
57
+
58
+ Bridgetown.logger.info("Converters:", site.converters.length.to_s.yellow.bold)
59
+
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
67
+
68
+ Bridgetown.logger.info("Generators:", site.generators.length.to_s.yellow.bold)
69
+
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
113
+
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")
128
+ end
129
+ end
130
+
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
138
+
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
146
+
147
+ run "git clone https://github.com/bridgetownrb/bridgetown-sample-plugin #{name}"
148
+ new_gemspec = "#{name}.gemspec"
149
+
150
+ inside name do # rubocop:todo Metrics/BlockLength
151
+ run "rm -rf .git"
152
+ run "git init"
153
+
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
159
+
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
162
+
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
166
+
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
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
194
+
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
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end