@@ -262,13 +262,29 @@ static AST_NODE_T* transform_tag_helper_with_attributes(
262262 if (parse_context -> info -> call_node && handler -> extract_content ) {
263263 helper_content = handler -> extract_content (parse_context -> info -> call_node , & parse_context -> parser , allocator );
264264
265- if (helper_content && parse_context -> info -> call_node -> arguments ) {
266- if (strcmp (handler -> name , "content_tag" ) == 0 && parse_context -> info -> call_node -> arguments -> arguments .size >= 2 ) {
267- content_is_ruby_expression =
268- (parse_context -> info -> call_node -> arguments -> arguments .nodes [1 ]-> type != PM_STRING_NODE );
269- } else if (parse_context -> info -> call_node -> arguments -> arguments .size >= 1 ) {
270- content_is_ruby_expression =
271- (parse_context -> info -> call_node -> arguments -> arguments .nodes [0 ]-> type != PM_STRING_NODE );
265+ if (helper_content ) {
266+ pm_call_node_t * call = parse_context -> info -> call_node ;
267+
268+ if (call -> arguments ) {
269+ if (strcmp (handler -> name , "content_tag" ) == 0 && call -> arguments -> arguments .size >= 2
270+ && call -> arguments -> arguments .nodes [1 ]-> type != PM_KEYWORD_HASH_NODE ) {
271+ content_is_ruby_expression = (call -> arguments -> arguments .nodes [1 ]-> type != PM_STRING_NODE );
272+ } else if (strcmp (handler -> name , "content_tag" ) != 0 && call -> arguments -> arguments .size >= 1
273+ && call -> arguments -> arguments .nodes [0 ]-> type != PM_KEYWORD_HASH_NODE ) {
274+ content_is_ruby_expression = (call -> arguments -> arguments .nodes [0 ]-> type != PM_STRING_NODE );
275+ }
276+ }
277+
278+ if (!content_is_ruby_expression && call -> block && call -> block -> type == PM_BLOCK_NODE ) {
279+ pm_block_node_t * block_node = (pm_block_node_t * ) call -> block ;
280+
281+ if (block_node -> body && block_node -> body -> type == PM_STATEMENTS_NODE ) {
282+ pm_statements_node_t * statements = (pm_statements_node_t * ) block_node -> body ;
283+
284+ if (statements -> body .size == 1 ) {
285+ content_is_ruby_expression = (statements -> body .nodes [0 ]-> type != PM_STRING_NODE );
286+ }
287+ }
272288 }
273289 }
274290 }
@@ -492,7 +508,9 @@ static AST_NODE_T* transform_link_to_helper(
492508
493509 hb_array_T * attributes = NULL ;
494510 pm_arguments_node_t * link_arguments = info -> call_node -> arguments ;
495- bool keyword_hash_is_url = link_arguments && link_arguments -> arguments .size == 2
511+ bool has_inline_block = info -> call_node -> block && info -> call_node -> block -> type == PM_BLOCK_NODE ;
512+
513+ bool keyword_hash_is_url = !has_inline_block && link_arguments && link_arguments -> arguments .size == 2
496514 && link_arguments -> arguments .nodes [1 ]-> type == PM_KEYWORD_HASH_NODE ;
497515
498516 if (!keyword_hash_is_url ) {
@@ -549,7 +567,12 @@ static AST_NODE_T* transform_link_to_helper(
549567 pm_arguments_node_t * arguments = info -> call_node -> arguments ;
550568 pm_node_t * href_argument = NULL ;
551569
552- if (arguments -> arguments .size >= 2 ) {
570+ if (has_inline_block ) {
571+ if (arguments -> arguments .size >= 1 ) {
572+ href_argument = arguments -> arguments .nodes [0 ];
573+ href_is_ruby_expression = (href_argument -> type != PM_STRING_NODE );
574+ }
575+ } else if (arguments -> arguments .size >= 2 ) {
553576 href_argument = arguments -> arguments .nodes [1 ];
554577 href_is_ruby_expression = (href_argument -> type != PM_STRING_NODE );
555578 } else if (arguments -> arguments .size == 1 ) {
@@ -602,7 +625,17 @@ static AST_NODE_T* transform_link_to_helper(
602625 if (info -> content ) {
603626 bool content_is_ruby_expression = false;
604627
605- if (info -> call_node && info -> call_node -> arguments && info -> call_node -> arguments -> arguments .size >= 1 ) {
628+ if (has_inline_block && info -> call_node -> block && info -> call_node -> block -> type == PM_BLOCK_NODE ) {
629+ pm_block_node_t * block_node = (pm_block_node_t * ) info -> call_node -> block ;
630+
631+ if (block_node -> body && block_node -> body -> type == PM_STATEMENTS_NODE ) {
632+ pm_statements_node_t * statements = (pm_statements_node_t * ) block_node -> body ;
633+
634+ if (statements -> body .size == 1 ) {
635+ content_is_ruby_expression = (statements -> body .nodes [0 ]-> type != PM_STRING_NODE );
636+ }
637+ }
638+ } else if (info -> call_node && info -> call_node -> arguments && info -> call_node -> arguments -> arguments .size >= 1 ) {
606639 pm_node_t * first_argument = info -> call_node -> arguments -> arguments .nodes [0 ];
607640 content_is_ruby_expression = (first_argument -> type != PM_STRING_NODE );
608641 }
0 commit comments