Class: MKBrut::Segments::BareBones

Inherits:
Base
  • Object
show all
Defined in:
lib/mkbrut/segments/bare_bones.rb

Overview

The bare bones configuration on top of a blank Brut app.

Defined Under Namespace

Classes: InsertCustomElement, InsertEndToEndTestCode

Constant Summary

Constants included from MKBrut

VERSION

Instance Attribute Summary

Attributes inherited from Base

#project_root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#create!

Constructor Details

#initialize(app_options:, current_dir:, templates_dir:) ⇒ BareBones



6
7
8
9
10
# File 'lib/mkbrut/segments/bare_bones.rb', line 6

def initialize(app_options:, current_dir:, templates_dir:)
  @project_root  = current_dir / app_options.app_name
  @templates_dir = templates_dir / "segments" / "BareBones"
  @erb_binding   = ErbBindingDelegate.new(app_options)
end

Class Method Details

.friendly_nameObject



4
# File 'lib/mkbrut/segments/bare_bones.rb', line 4

def self.friendly_name = "Bare bones framing"

Instance Method Details

#<=>(other) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/mkbrut/segments/bare_bones.rb', line 12

def <=>(other)
  if self.class == other.class
    0
  else
    -1
  end
end

#add!Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/mkbrut/segments/bare_bones.rb', line 20

def add!

  operations = copy_files(@templates_dir, @project_root) + 
               other_operations(@project_root)

  operations.each do |operation|
    operation.call
  end

end

#other_operations(project_root) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
# File 'lib/mkbrut/segments/bare_bones.rb', line 31

def other_operations(project_root)
  [
    MKBrut::Ops::InsertRoute.new(
      project_root: @project_root,
      code: %{path "/trigger_exception", method: :get}
    ),
    MKBrut::Ops::InsertCodeInMethod.new(
      file: @project_root / "app" / "src" / "app.rb",
      class_name: "App",
      method_name: "initialize",
      code: %{
Brut.container.store(
"trigger_exception_key",
String,
"String used to prevent anyone from triggering exceptions in TriggerExceptionHandler"
) do
ENV.fetch("TRIGGER_EXCEPTION_KEY")
end},
    ),
    InsertCustomElement.new(
      project_root: @project_root,
      element_class_name: "Example",
    ),
    MKBrut::Ops::InsertCodeInMethod.new(
      file: @project_root / "app" / "src" / "front_end" / "pages" / "home_page.rb",
      class_name: "HomePage",
      method_name: "page_template",
      code: %{
#{ @erb_binding.prefix }_example(
transform: "upper",
class: [ "pos-fixed",
         "bottom-0",
         "left-0",
         "w-100",
         "ff-sans",
         "lh-title",
         "tracked",
         "f-5",
         "f-6-ns",
         "tc",
         "pa-3",
         "mt-3",
         "db", ]
) do
"We Like the Web"
end
}
    ),
    InsertEndToEndTestCode.new(
      file: @project_root / "specs" / "e2e" / "home_page.spec.rb",
      code: %{
  example = page.locator("#{ @erb_binding.prefix }-example")
  # The #{ @erb_binding.prefix }-example custom element will transform
  # the text it contains.  Since this is an end-to-end test
  # the element should've done its thing and given us 
  # upper-case text.
  expect(example).to have_text("WE LIKE THE WEB") }
    ),
    MKBrut::Ops::AppendToFile.new(
      file: @project_root / ".env.development",
      content: %{
# Key used to allow triggering an exception. This is required to prevent
# just anyone from triggering one.
TRIGGER_EXCEPTION_KEY=dev-trigger-exception
}
    ),
    MKBrut::Ops::AppendToFile.new(
      file: @project_root / ".env.test",
      content: "TRIGGER_EXCEPTION_KEY=test-trigger-exception"
    ),

  ]
end