<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="340521" data-post-id="340521">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="cmo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmo/120/19618_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  cmo
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>You can use <code>epp_dodger</code> to parse the Erlang file, rather than fiddling with strings.</p>
<p>e.g (though I prefer how you handle the key constants)</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule WxInclude do
  @moduledoc """
  Creates functions for all the `wx` constants in `wx/include/wx.hrl`.

  Function names match the constants except for the key codes, which we prepend `wx` onto, such that `WXK_NONE` becomes `wxWXK_NONE()`

  ## Usage

      defmodule MyApp.Ui do
        import WxInclude

        def init(_) do
          wx = :wx.new()

          frame =
            :wxFrame.new(
              wx,
              wxID_ANY(),
              'Cool Title',
              size: {800, 600},
              style: wxSYSTEM_MENU() ||| wxCAPTION() ||| wxMINIMIZE_BOX() ||| wxCLOSE_BOX() ||| wxCLIP_CHILDREN()
            )

          ...

          {frame, state}
        end
      end
  """
  lib_dir = :code.lib_dir(:wx)
  file = :filename.join([lib_dir, ~c"include/wx.hrl"])

  {:ok, forms} = :epp_dodger.parse_file(file)

  defines =
    for {:tree, :attribute, _, {_, {:atom, _, :define}, [{type, _, name} | _]}} &lt;- forms do
      {type, name}
    end

  gets =
    Stream.map(defines, fn
      {:atom, const} -&gt; "get(#{const}) -&gt; ?#{const}"
      {:var, const} -&gt; "get(wx#{const}) -&gt; ?#{const}"
    end)
    |&gt; Enum.join(";\n")

  contents = """
  -module(wx_include).
  -include_lib("wx/include/wx.hrl").
  -export([get/1]).

  #{gets}.
  """

  File.write!(
    __DIR__ &lt;&gt; "/../src/wx_include.erl",
    contents
  )

  for {type, const} &lt;- defines do
    const =
      case type do
        :atom -&gt; const
        :var -&gt; "wx#{const}"
      end

    Module.eval_quoted(
      __MODULE__,
      Code.string_to_quoted("def #{const}, do: :wx_include.get(:#{const})")
    )
  end
end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="340521" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/wxex-elixir-wrappers-for-macros-and-records-in-wx/66209/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-340521" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="340521"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>