Class: Fresco::CLI::Build

Inherits:
Object
  • Object
show all
Defined in:
lib/fresco/cli/build.rb

Constant Summary collapse

GEN_DIR =
"generated".freeze
VIEWS_GEN_DIR =
"#{GEN_DIR}/views".freeze
MODELS_GEN_DIR =
"#{GEN_DIR}/models".freeze
RUNTIME_GEN_DIR =

C shims get copied here so the ‘ffi_cflags “generated/runtime/*.c”` strings in the runtime templates resolve from the user app’s cwd.

"#{GEN_DIR}/runtime".freeze
TEMPLATES_DIR =

In-gem source roots (set once at load — Fresco::Paths resolves relative to lib/fresco/paths.rb, which is stable per-install).

Fresco::Paths.template_root
RUNTIME_DIR =
Fresco::Paths.runtime_root
NAME_CHAR =
/[A-Za-z0-9_]/.freeze
PARTIAL_RENDER_RE =

Partial render call rewrite — see resolve_partial / rewrite_partial_renders.

/<%=\s*render(?:\s*\(\s*|\s+)partial:\s*["']([^"']+)["'](?:\s*,\s*locals:\s*\{(.*?)\})?\s*\)?\s*%>/m
LAYOUT_FRAMEWORK_KWARGS =

Fresco-supplied kwargs every layout receives.

"flash: Flash.new, content: \"\"".freeze
LOCALS_RE =
/\A\s*<%#\s*locals:\s*(\(.*?\))\s*%>\s*\r?\n?/.freeze
LAYOUT_YIELD_RE =
/<%=\s*yield\s*%>/.freeze
STATIC_APPEND_PREFIX =
"_buf << '".freeze
STATIC_APPEND_SUFFIX =
"'.freeze".freeze
MAX_VIEW_LITERAL_BYTES =
512

Instance Method Summary collapse

Instance Method Details

#run(argv = []) ⇒ Object



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
# File 'lib/fresco/cli/build.rb', line 43

def run(argv = [])
  FileUtils.mkdir_p(GEN_DIR)
  FileUtils.mkdir_p(VIEWS_GEN_DIR)
  FileUtils.mkdir_p(RUNTIME_GEN_DIR)

  lint_actions!
  action_files = stub_action_classes
  route_entries = load_routes
  has_root = route_entries.any? { |verb, pattern, _, _| verb == "GET" && pattern == "/" }

  emit_welcome(has_root, route_entries)
  emit_dispatch(route_entries)
  emit_runtime
  emit_c_shims
  db_adapter = emit_db_adapter
  emit_models(db_adapter)
  generated_models = collect_generated_models
  emit_migrations(db_adapter)
  emit_requires_manifest(action_files, generated_models, has_root)
  emit_boot
  view_names, layout_names = emit_views
  emit_layout_dispatch(layout_names)

  puts "wrote #{GEN_DIR}/{boot,dispatch,layout_dispatch,requires,runtime,views}.rb " \
       "(#{route_entries.size} routes, #{view_names.size} views, #{layout_names.size} layouts)"
  0
end