Module: Herb
- Defined in:
- lib/herb.rb,
lib/herb.rb,
lib/herb/ast.rb,
lib/herb/range.rb,
lib/herb/token.rb,
lib/herb/colors.rb,
lib/herb/engine.rb,
lib/herb/errors.rb,
lib/herb/result.rb,
lib/herb/project.rb,
lib/herb/version.rb,
lib/herb/visitor.rb,
lib/herb/ast/node.rb,
lib/herb/location.rb,
lib/herb/position.rb,
lib/herb/warnings.rb,
lib/herb/ast/nodes.rb,
lib/herb/bootstrap.rb,
lib/herb/html/util.rb,
lib/herb/dev/runner.rb,
lib/herb/dev/server.rb,
lib/herb/lex_result.rb,
lib/herb/token_list.rb,
lib/herb/ast/helpers.rb,
lib/herb/diff_result.rb,
lib/herb/parse_result.rb,
lib/herb/configuration.rb,
lib/herb/prism_inspect.rb,
lib/herb/diff_operation.rb,
lib/herb/parser_options.rb,
lib/herb/engine/compiler.rb,
lib/herb/dev/server_entry.rb,
lib/herb/engine/validator.rb,
lib/herb/ast/erb_render_node.rb,
lib/herb/ast/erb_content_node.rb,
lib/herb/engine/debug_visitor.rb,
lib/herb/engine/error_formatter.rb,
lib/herb/engine/validation_errors.rb,
lib/herb/action_view/helper_registry.rb,
lib/herb/action_view/render_analyzer.rb,
lib/herb/engine/parser_error_overlay.rb,
lib/herb/engine/validation_error_overlay.rb,
lib/herb/engine/validators/render_validator.rb,
lib/herb/engine/validators/nesting_validator.rb,
lib/herb/engine/validators/security_validator.rb,
lib/herb/engine/validators/accessibility_validator.rb,
sig/herb.rbs,
sig/herb.rbs,
sig/herb/ast.rbs,
sig/herb/range.rbs,
sig/herb/token.rbs,
sig/serialized.rbs,
sig/herb/colors.rbs,
sig/herb/engine.rbs,
sig/herb/errors.rbs,
sig/herb/result.rbs,
sig/herb/version.rbs,
sig/herb/visitor.rbs,
sig/herb/ast/node.rbs,
sig/herb/location.rbs,
sig/herb/position.rbs,
sig/herb/warnings.rbs,
sig/herb/ast/nodes.rbs,
sig/herb/bootstrap.rbs,
sig/herb/html/util.rbs,
sig/herb/dev/runner.rbs,
sig/herb/dev/server.rbs,
sig/herb/lex_result.rbs,
sig/herb/token_list.rbs,
sig/herb/ast/helpers.rbs,
sig/herb/diff_result.rbs,
sig/herb_c_extension.rbs,
sig/herb/engine/debug.rbs,
sig/herb/parse_result.rbs,
sig/herb/configuration.rbs,
sig/herb/prism_inspect.rbs,
sig/herb/diff_operation.rbs,
sig/herb/parser_options.rbs,
sig/herb/engine/compiler.rbs,
sig/serialized_ast_nodes.rbs,
sig/herb/dev/server_entry.rbs,
sig/herb/engine/validator.rbs,
sig/serialized_ast_errors.rbs,
sig/herb/ast/erb_render_node.rbs,
sig/herb/ast/erb_content_node.rbs,
sig/herb/engine/debug_visitor.rbs,
sig/herb/engine/error_formatter.rbs,
sig/herb/engine/validation_errors.rbs,
sig/herb/action_view/helper_registry.rbs,
sig/herb/action_view/render_analyzer.rbs,
sig/herb/engine/parser_error_overlay.rbs,
sig/herb/engine/validation_error_overlay.rbs,
sig/herb/engine/validators/render_validator.rbs,
sig/herb/engine/validators/nesting_validator.rbs,
sig/herb/engine/validators/security_validator.rbs,
sig/herb/engine/validators/accessibility_validator.rbs,
ext/herb/extension.c
Overview
NOTE: This file is generated by the templates/template.rb script and should not be modified manually. See /home/runner/work/herb/herb/templates/lib/herb/action_view/helper_registry.rb.erb
Defined Under Namespace
Modules: AST, ActionView, Bootstrap, Colors, Dev, Errors, HTML, PrismInspect, Warnings Classes: CLI, Configuration, DiffOperation, DiffResult, Engine, LexResult, Location, ParseResult, ParserOptions, Position, Project, Range, Result, Token, TokenList, Visitor
Constant Summary collapse
- PARTIAL_EXTENSIONS =
[ ".html.erb", ".html.herb", ".erb", ".herb", ".turbo_stream.erb", ".turbo_stream.herb" ].freeze
- PARTIAL_GLOB_PATTERN =
"_*.{html.erb,html.herb,erb,herb,turbo_stream.erb,turbo_stream.herb}"- VERSION =
"0.10.2"
Class Method Summary collapse
- .arena_stats(*args) ⇒ Object
- .configuration(project_path = nil) ⇒ Object
- .configure(project_path = nil) ⇒ Object
- .dev_server_port(project_path = nil) ⇒ Object
- .diff(*args) ⇒ Object
- .ensure_installed(&block) ⇒ void
- .extract_html(source) ⇒ String
- .extract_ruby(*args) ⇒ String
- .leak_check(source) ⇒ Object
- .lex(*args) ⇒ LexResult
-
.lex_file(path) ⇒ LexResult
: (String path, ?arena_stats: bool) -> LexResult.
- .parse(*args) ⇒ ParseResult
-
.parse_file(path) ⇒ ParseResult
: (String path, ?track_whitespace: bool, ?analyze: bool, ?strict: bool, ?action_view_helpers: bool, ?transform_conditionals: bool, ?strict_locals: bool, ?prism_nodes: bool, ?prism_nodes_deep: bool, ?prism_program: bool, ?arena_stats: bool) -> ParseResult.
-
.parse_ruby(source) ⇒ Prism::ParseResult
: (String source) -> Prism::ParseResult.
- .reset_configuration! ⇒ Object
- .version ⇒ String
Class Method Details
.arena_stats(*args) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'ext/herb/extension.c', line 263
static VALUE Herb_arena_stats(int argc, VALUE* argv, VALUE self) {
VALUE source, options;
rb_scan_args(argc, argv, "1:", &source, &options);
char* string = (char*) check_string(source);
parser_options_T parser_options = HERB_DEFAULT_PARSER_OPTIONS;
if (!NIL_P(options)) {
VALUE track_whitespace = rb_hash_lookup(options, rb_utf8_str_new_cstr("track_whitespace"));
if (NIL_P(track_whitespace)) { track_whitespace = rb_hash_lookup(options, ID2SYM(rb_intern("track_whitespace"))); }
if (!NIL_P(track_whitespace) && RTEST(track_whitespace)) { parser_options.track_whitespace = true; }
VALUE analyze = rb_hash_lookup(options, rb_utf8_str_new_cstr("analyze"));
if (NIL_P(analyze)) { analyze = rb_hash_lookup(options, ID2SYM(rb_intern("analyze"))); }
if (!NIL_P(analyze) && !RTEST(analyze)) { parser_options.analyze = false; }
VALUE strict = rb_hash_lookup(options, rb_utf8_str_new_cstr("strict"));
if (NIL_P(strict)) { strict = rb_hash_lookup(options, ID2SYM(rb_intern("strict"))); }
if (!NIL_P(strict)) { parser_options.strict = RTEST(strict); }
}
hb_allocator_T allocator;
if (!hb_allocator_init(&allocator, HB_ALLOCATOR_ARENA)) { return Qnil; }
AST_DOCUMENT_NODE_T* root = herb_parse(string, &parser_options, &allocator);
hb_arena_stats_T stats = hb_arena_get_stats((hb_arena_T*) allocator.context);
if (root != NULL) { ast_node_free((AST_NODE_T*) root, &allocator); }
hb_allocator_destroy(&allocator);
VALUE hash = rb_hash_new();
rb_hash_aset(hash, ID2SYM(rb_intern("pages")), SIZET2NUM(stats.pages));
rb_hash_aset(hash, ID2SYM(rb_intern("total_capacity")), SIZET2NUM(stats.total_capacity));
rb_hash_aset(hash, ID2SYM(rb_intern("total_used")), SIZET2NUM(stats.total_used));
rb_hash_aset(hash, ID2SYM(rb_intern("total_available")), SIZET2NUM(stats.total_available));
rb_hash_aset(hash, ID2SYM(rb_intern("allocations")), SIZET2NUM(stats.allocations));
rb_hash_aset(hash, ID2SYM(rb_intern("fragmentation")), SIZET2NUM(stats.fragmentation));
rb_hash_aset(hash, ID2SYM(rb_intern("default_page_size")), SIZET2NUM(stats.default_page_size));
return hash;
}
|
.configuration(project_path = nil) ⇒ Object
100 101 102 |
# File 'lib/herb.rb', line 100 def configuration(project_path = nil) @configuration ||= Configuration.load(project_path) end |
.configure(project_path = nil) ⇒ Object
104 105 106 |
# File 'lib/herb.rb', line 104 def configure(project_path = nil) @configuration = Configuration.load(project_path) end |
.dev_server_port(project_path = nil) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/herb.rb', line 112 def dev_server_port(project_path = nil) require_relative "herb/dev/server_entry" project_path ||= Dir.pwd entry = Dev::ServerEntry.find_by_project(project_path) entry&.port rescue StandardError nil end |
.diff(*args) ⇒ Object
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
# File 'ext/herb/extension.c', line 497
static VALUE Herb_diff(int argc, VALUE* argv, VALUE self) {
VALUE old_source, new_source;
rb_scan_args(argc, argv, "2", &old_source, &new_source);
char* old_string = (char*) check_string(old_source);
char* new_string = (char*) check_string(new_source);
diff_args_T args = { 0 };
parser_options_T parser_options = HERB_DEFAULT_PARSER_OPTIONS;
if (!hb_allocator_init(&args.old_allocator, HB_ALLOCATOR_ARENA)) { return Qnil; }
if (!hb_allocator_init(&args.new_allocator, HB_ALLOCATOR_ARENA)) {
hb_allocator_destroy(&args.old_allocator);
return Qnil;
}
if (!hb_allocator_init(&args.diff_allocator, HB_ALLOCATOR_ARENA)) {
hb_allocator_destroy(&args.old_allocator);
hb_allocator_destroy(&args.new_allocator);
return Qnil;
}
args.old_root = herb_parse(old_string, &parser_options, &args.old_allocator);
args.new_root = herb_parse(new_string, &parser_options, &args.new_allocator);
if (args.old_root == NULL || args.new_root == NULL) {
diff_cleanup((VALUE) &args);
return Qnil;
}
args.diff_result = herb_diff(args.old_root, args.new_root, &args.diff_allocator);
return rb_ensure(diff_convert_body, (VALUE) &args, diff_cleanup, (VALUE) &args);
}
|
.ensure_installed(&block) ⇒ void
This method returns an undefined value.
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/herb.rb', line 122 def ensure_installed(&block) require "bundler/inline" verbose = $VERBOSE $VERBOSE = nil gemfile(true, quiet: true) do # steep:ignore source "https://rubygems.org" # steep:ignore instance_eval(&block) # steep:ignore end ensure $VERBOSE = verbose end |
.extract_html(source) ⇒ String
247 |
# File 'ext/herb/extension.c', line 247
def self.extract_html: (String source) -> String
|
.extract_ruby(*args) ⇒ String
210 |
# File 'ext/herb/extension.c', line 210
def self.extract_ruby: (String source, ?semicolons: bool, ?comments: bool, ?preserve_positions: bool) -> String
|
.leak_check(source) ⇒ Object
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'ext/herb/extension.c', line 332
static VALUE Herb_leak_check(VALUE self, VALUE source) {
char* string = (char*) check_string(source);
VALUE result = rb_hash_new();
{
hb_allocator_T allocator;
if (!hb_allocator_init(&allocator, HB_ALLOCATOR_TRACKING)) { return Qnil; }
hb_array_T* tokens = herb_lex(string, &allocator);
if (tokens != NULL) { herb_free_tokens(&tokens, &allocator); }
hb_allocator_tracking_stats_T* stats = hb_allocator_tracking_stats(&allocator);
rb_hash_aset(result, ID2SYM(rb_intern("lex")), make_tracking_hash(stats));
hb_allocator_destroy(&allocator);
}
{
hb_allocator_T allocator;
if (!hb_allocator_init(&allocator, HB_ALLOCATOR_TRACKING)) { return Qnil; }
parser_options_T parser_options = HERB_DEFAULT_PARSER_OPTIONS;
AST_DOCUMENT_NODE_T* root = herb_parse(string, &parser_options, &allocator);
if (root != NULL) { ast_node_free((AST_NODE_T*) root, &allocator); }
hb_allocator_tracking_stats_T* stats = hb_allocator_tracking_stats(&allocator);
rb_hash_aset(result, ID2SYM(rb_intern("parse")), make_tracking_hash(stats));
hb_allocator_destroy(&allocator);
}
{
hb_allocator_T allocator;
if (!hb_allocator_init(&allocator, HB_ALLOCATOR_TRACKING)) { return Qnil; }
hb_buffer_T output;
if (!hb_buffer_init(&output, strlen(string), &allocator)) { return Qnil; }
herb_extract_ruby_options_T extract_options = HERB_EXTRACT_RUBY_DEFAULT_OPTIONS;
herb_extract_ruby_to_buffer_with_options(string, &output, &extract_options, &allocator);
hb_allocator_tracking_stats_T* stats = hb_allocator_tracking_stats(&allocator);
rb_hash_aset(result, ID2SYM(rb_intern("extract_ruby")), make_tracking_hash(stats));
hb_buffer_free(&output);
hb_allocator_destroy(&allocator);
}
{
hb_allocator_T allocator;
if (!hb_allocator_init(&allocator, HB_ALLOCATOR_TRACKING)) { return Qnil; }
hb_buffer_T output;
if (!hb_buffer_init(&output, strlen(string), &allocator)) { return Qnil; }
herb_extract_html_to_buffer(string, &output, &allocator);
hb_allocator_tracking_stats_T* stats = hb_allocator_tracking_stats(&allocator);
rb_hash_aset(result, ID2SYM(rb_intern("extract_html")), make_tracking_hash(stats));
hb_buffer_free(&output);
hb_allocator_destroy(&allocator);
}
return result;
}
|
.lex(*args) ⇒ LexResult
86 |
# File 'ext/herb/extension.c', line 86
def self.lex: (String input, ?arena_stats: bool) -> LexResult
|
.lex_file(path) ⇒ LexResult
: (String path, ?arena_stats: bool) -> LexResult
84 85 86 |
# File 'lib/herb.rb', line 84 def lex_file(path, **) lex(File.read(path), **) end |
.parse(*args) ⇒ ParseResult
111 |
# File 'ext/herb/extension.c', line 111
def self.parse: (String input, ?track_whitespace: bool, ?analyze: bool, ?strict: bool, ?action_view_helpers: bool, ?transform_conditionals: bool, ?dot_notation_tags: bool, ?render_nodes: bool, ?strict_locals: bool, ?prism_nodes: bool, ?prism_nodes_deep: bool, ?prism_program: bool, ?html: bool, ?arena_stats: bool) -> ParseResult
|
.parse_file(path) ⇒ ParseResult
: (String path, ?track_whitespace: bool, ?analyze: bool, ?strict: bool, ?action_view_helpers: bool, ?transform_conditionals: bool, ?strict_locals: bool, ?prism_nodes: bool, ?prism_nodes_deep: bool, ?prism_program: bool, ?arena_stats: bool) -> ParseResult
89 90 91 |
# File 'lib/herb.rb', line 89 def parse_file(path, **) parse(File.read(path), **) end |
.parse_ruby(source) ⇒ Prism::ParseResult
: (String source) -> Prism::ParseResult
94 95 96 97 98 |
# File 'lib/herb.rb', line 94 def parse_ruby(source) require "prism" Prism.parse(source) end |
.reset_configuration! ⇒ Object
108 109 110 |
# File 'lib/herb.rb', line 108 def reset_configuration! @configuration = nil end |
.version ⇒ String
399 |
# File 'ext/herb/extension.c', line 399
def self.version: () -> String
|