heterocephalus icon indicating copy to clipboard operation
heterocephalus copied to clipboard

Feature request: comment syntax

Open dahlia opened this issue 6 years ago • 14 comments

Sometimes we need to explain the intention of a templating code. Comments can be useful for such situations. Though I have no idea how the comment syntax should look like.

dahlia avatar Mar 09 '18 20:03 dahlia

Thanks for an issue.

Heterocephalus is supposed to be used with another template engine. So, we can use comment syntax of the other template engine.

For example, if we are using pug, we can inject any comment as follows.

.someBlock
  | %{forall paragraph <- lines paragraphs}
  p.someBlock_paragraph
    // This is comment syntax for pug
    | \#{ paragraph }
  | %{endforall}

Even with a raw HTML, we can use comment like bellow example.

<div class="someBlock">
    %{forall paragraph <- lines paragraphs}
    <p class="someBlock_paragraph">
        <!-- This is comment syntax for html -->
        \#{ paragraph }
    </p>
    %{endforall}
</div>

Is this work for your intention?

arowM avatar Mar 10 '18 15:03 arowM

Yeah, I indeed am using that workaround. The result code contains the comments and I thought it may deliver false intentions or things that I don't want to expose to who can read the result code. On Sun, Mar 11, 2018 at 0:23 Kadzuya OKAMOTO [email protected] wrote:

Thanks for an issue.

Heterocephalus is supposed to be used with another template engine. So, we can use comment syntax of the other template engine.

For example, if we are using pug, we can inject any comment as follows.

.someBlock | %{forall paragraph <- lines paragraphs} p.someBlock_paragraph // This is comment syntax for pug | #{ paragraph } | %{endforall}

Even with a raw HTML, we can use comment like bellow example.

%{forall paragraph \#{ paragraph } %{endforall}

Is this works for your intention?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/arowM/heterocephalus/issues/21#issuecomment-372037891, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAwj2Pv3VD1d24KxifiAnN_zSf_X4fmks5tc_AEgaJpZM4Sk2_u .

dahlia avatar Mar 10 '18 16:03 dahlia

Note, for comparison, Hamlet supports one-line comments prefixed with $#. I'm not sure it's documented, and I might have sigils in reverse order, but there are definitely Hamlet-level comments. :)

On Mar 10, 2018 11:02, "Hong Minhee" [email protected] wrote:

Yeah, I indeed am using that workaround. The result code contains the comments and I thought it may deliver false intentions or things that I don't want to expose to who can read the result code. On Sun, Mar 11, 2018 at 0:23 Kadzuya OKAMOTO [email protected] wrote:

Thanks for an issue.

Heterocephalus is supposed to be used with another template engine. So, we can use comment syntax of the other template engine.

For example, if we are using pug, we can inject any comment as follows.

.someBlock | %{forall paragraph <- lines paragraphs} p.someBlock_paragraph // This is comment syntax for pug | #{ paragraph } | %{endforall}

Even with a raw HTML, we can use comment like bellow example.

%{forall paragraph \#{ paragraph } %{endforall}

Is this works for your intention?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <https://github.com/arowM/heterocephalus/issues/21# issuecomment-372037891>, or mute the thread <https://github.com/notifications/unsubscribe- auth/AAAwj2Pv3VD1d24KxifiAnN_zSf_X4fmks5tc_AEgaJpZM4Sk2_u> .

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/arowM/heterocephalus/issues/21#issuecomment-372040705, or mute the thread https://github.com/notifications/unsubscribe-auth/AAg3qsdb6J4ux-hS6j8sC0ENy-8aTDCpks5tc_kOgaJpZM4Sk2_u .

chreekat avatar Mar 10 '18 16:03 chreekat

@dahlia Thanks. It makes sense! Then how about this work around?

<div class="someBlock">
    %{forall paragraph <- lines paragraphs}
    <p class="someBlock_paragraph">
        \#{ comment "This is a comment." }
        \#{ paragraph }
    </p>
    %{endforall}
</div>
comment :: String -> String
comment = const ""

arowM avatar Mar 11 '18 05:03 arowM

@chreekat Thanks for helpful information.

I do not want to introduce new syntaxes by the reason of just convenience because it is easy to add new feature but it is difficult to remove it after released it. To tell the truth, I don't know it's worth valuable to introduce comment syntax. Would you be able to lend your expertise?

arowM avatar Mar 11 '18 05:03 arowM

This point would be best made with concrete examples. @dahlia, do you have any to share? I will look to see if I have any, also.

chreekat avatar Mar 11 '18 15:03 chreekat

Is there any opinions, @dahlia ?

arowM avatar Jun 11 '18 15:06 arowM

Actually I use Heterocephalus for generating Python and JavaScript codes. As they both have their own comments, I currently stick with a workround mentioned above. The problem is that its content is out of scope and merely nonsense for people who read the generated codes.

dahlia avatar Jun 12 '18 05:06 dahlia

Thanks. What do you think about this idea using comment function?

arowM avatar Jun 12 '18 13:06 arowM

Although using a no-op function barely works, since its syntax is quite picky (e.g., need to escape a double quote), I personally am not likely to use that.

dahlia avatar Jun 12 '18 14:06 dahlia

OK. It makes sense. The other reason, I think, to introduce special notation is to improve readability.

@dahlia , are you interested in taking a stab at a PR?

arowM avatar Jun 12 '18 14:06 arowM

I meant if you are not interested in creating PR by yourself, I'll do it by myself. I'll assume this issue is not actually important for you if there are no replies from you in a week from today, @dahlia .

arowM avatar Aug 05 '18 12:08 arowM

Sorry for the late response. I would appreciate if you're going to add the own comment syntax to Heterocephalus. 😄

dahlia avatar Aug 08 '18 10:08 dahlia

Thanks for response! I'll do it.

arowM avatar Aug 08 '18 13:08 arowM