Class: Bootstrap::Generators::SnippetBase
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Bootstrap::Generators::SnippetBase
show all
- Defined in:
- lib/generators/bootstrap/snippets/snippet_base.rb
Overview
Shared behaviour for the per-category snippet generators (bootstrap:header,
bootstrap:hero, ...). Each subclass only declares which docs category it
serves; everything else lives here.
Direct Known Subclasses
BadgeGenerator, BreadcrumbGenerator, ButtonGenerator, DropdownGenerator, FeaturesGenerator, FooterGenerator, HeaderGenerator, HeroGenerator, JumbotronGenerator, ListGroupGenerator, ModalGenerator, SidebarGenerator
Constant Summary
collapse
- ICONS_PARTIAL =
'bootstrap_icons'.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.banner ⇒ Object
35
36
37
|
# File 'lib/generators/bootstrap/snippets/snippet_base.rb', line 35
def self.banner
"rails generate #{namespace} [VARIANT] [options]"
end
|
.snippet_category(category = nil) ⇒ Object
Subclasses call snippet_category "headers".
26
27
28
29
|
# File 'lib/generators/bootstrap/snippets/snippet_base.rb', line 26
def self.snippet_category(category = nil)
@snippet_category = category if category
@snippet_category
end
|
.source_root ⇒ Object
31
32
33
|
# File 'lib/generators/bootstrap/snippets/snippet_base.rb', line 31
def self.source_root
File.expand_path("../templates", __FILE__)
end
|
Instance Method Details
#copy_icons ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/generators/bootstrap/snippets/snippet_base.rb', line 55
def copy_icons
return if options[:list]
return unless variant[:icons] && options[:icons]
copy_file "icons/_#{ICONS_PARTIAL}.html.erb",
File.join(options[:path], "_#{ICONS_PARTIAL}.html.erb")
end
|
#copy_snippet ⇒ Object
49
50
51
52
53
|
# File 'lib/generators/bootstrap/snippets/snippet_base.rb', line 49
def copy_snippet
return if options[:list]
copy_file "#{category}/#{variant_name}.html.erb", partial_path
end
|
#list_variants ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/generators/bootstrap/snippets/snippet_base.rb', line 39
def list_variants
return unless options[:list]
say "#{category} variants:\n\n"
SnippetCatalog.variants(category).each do |v|
say format(" %-22s %s%s", v[:name], v[:description], v[:icons] ? " (uses icons)" : "")
end
say "\nDefault: #{SnippetCatalog.default_variant(category)}"
end
|
#report ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/generators/bootstrap/snippets/snippet_base.rb', line 63
def report
return if options[:list]
say "\nRender it with: <%= render \"#{render_path}\" %>"
if variant[:icons] && options[:icons]
say "The snippet uses Bootstrap Icons; render the sprite once in your layout:"
say " <%= render \"#{icons_render_path}\" %>"
end
if variant[:images]
say_status :warn,
"This snippet references placeholder images from the Bootstrap docs site " \
"(e.g. bootstrap-docs.png). They will 404 until you point them at your own assets.",
:yellow
end
end
|