Skip to content

Commit

Permalink
Syntax highlighting of c#, java, js, py, rb usages
Browse files Browse the repository at this point in the history
  • Loading branch information
generalmimon committed May 12, 2020
1 parent ca7f4b5 commit 4b5381c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 20 deletions.
21 changes: 17 additions & 4 deletions _build/usage_csharp.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@

<% class_name = ucc(file_id) %>
<pre><code class="csharp">var data = <%= class_name %>.FromFile("path/to/local/file.<%= meta['file-extension'] || meta['id'] %>");</code></pre>
<%= code cur_lang, <<-CODE
var data = #{ class_name }.FromFile("path/to/local/file.#{ meta['file-extension'] || meta['id'] }");
CODE
%>

<p>Or parse structure from a byte array:</p>

<pre><code class="csharp">byte[] someArray = new byte[] { ... };
var data = new <%= class_name %>(new KaitaiStream(someArray));</code></pre>
<%= code cur_lang, <<-CODE
byte[] someArray = new byte[] { ... };
var data = new #{ class_name }(new KaitaiStream(someArray));
CODE
%>

<p>After that, one can get various attributes from the structure by accessing properties like:</p>

<pre><code class="csharp"><% usage_attrs.each { |attr| %>data.<%= ucc(attr[:name]) %> // => <%= attr[:doc] %><% } %></code></pre>
<% src_usage_attrs = ""
usage_attrs.each { |attr|
src_usage_attrs += <<-CODE
data.#{ ucc(attr[:name]) } // => #{ attr[:doc] }
CODE
}
%>
<%= code cur_lang, src_usage_attrs %>
21 changes: 17 additions & 4 deletions _build/usage_java.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@

<% class_name = ucc(file_id) %>
<pre><code class="java"><%= class_name %> data = <%= class_name %>.fromFile("path/to/local/file.<%= meta['file-extension'] || format_name %>");</code></pre>
<%= code cur_lang, <<-CODE
#{ class_name } data = #{ class_name }.fromFile("path/to/local/file.#{ meta['file-extension'] || format_name }");
CODE
%>

<p>Or parse structure from a byte array:</p>

<pre><code class="java">byte[] someArray = new byte[] { ... };
<%= class_name %> data = new <%= class_name %>(new ByteBufferKaitaiStream(someArray));</code></pre>
<%= code cur_lang, <<-CODE
byte[] someArray = new byte[] { ... };
#{ class_name } data = new #{ class_name }(new ByteBufferKaitaiStream(someArray));
CODE
%>

<p>After that, one can get various attributes from the structure by invoking getter methods like:</p>

<pre><code class="java"><% usage_attrs.each { |attr| %>data.<%= lcc(attr[:name]) %>() // => <%= attr[:doc] %><% } %></code></pre>
<% src_usage_attrs = ""
usage_attrs.each { |attr|
src_usage_attrs += <<-CODE
data.#{ lcc(attr[:name]) }() // => #{ attr[:doc] }
CODE
}
%>
<%= code cur_lang, src_usage_attrs %>
16 changes: 13 additions & 3 deletions _build/usage_javascript.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@

<p>Parse structure from an ArrayBuffer:</p>

<pre><code class="javascript">var arrayBuffer = ...;
var data = new <%= class_name %>(new KaitaiStream(arrayBuffer));</code></pre>
<%= code cur_lang, <<-CODE
var arrayBuffer = ...;
var data = new #{ class_name }(new KaitaiStream(arrayBuffer));
CODE
%>

<p>After that, one can get various attributes from the structure by accessing fields or properties like:</p>

<pre><code class="javascript"><% usage_attrs.each { |attr| %>data.<%= lcc(attr[:name]) %> // => <%= attr[:doc] %><% } %></code></pre>
<% src_usage_attrs = ""
usage_attrs.each { |attr|
src_usage_attrs += <<-CODE
data.#{ lcc(attr[:name]) } // => #{ attr[:doc] }
CODE
}
%>
<%= code cur_lang, src_usage_attrs %>
23 changes: 18 additions & 5 deletions _build/usage_python.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@

<% class_name = ucc(file_id) %>
<pre><code class="python">data = <%= class_name %>.from_file("path/to/local/file.<%= meta['file-extension'] || format_name %>")</code></pre>
<%= code cur_lang, <<-CODE
data = #{ class_name }.from_file("path/to/local/file.#{ meta['file-extension'] || format_name }")
CODE
%>

<p>Or parse structure from a bytes:</p>

<pre><code class="python">from kaitaistruct import KaitaiStream, BytesIO
<%= code cur_lang, <<-CODE
from kaitaistruct import KaitaiStream, BytesIO
raw = b"\x00\x01\x02..."
data = <%= class_name %>(KaitaiStream(BytesIO(raw)))</code></pre>
raw = b"\\x00\\x01\\x02..."
data = #{ class_name }(KaitaiStream(BytesIO(raw)))
CODE
%>

<p>After that, one can get various attributes from the structure by invoking getter methods like:</p>

<pre><code class="python"><% usage_attrs.each { |attr| %>data.<%= attr[:name] %> # => <%= attr[:doc] %><% } %></code></pre>
<% src_usage_attrs = ""
usage_attrs.each { |attr|
src_usage_attrs += <<-CODE
data.#{ attr[:name] } # => #{ attr[:doc] }
CODE
}
%>
<%= code cur_lang, src_usage_attrs %>
21 changes: 17 additions & 4 deletions _build/usage_ruby.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@

<% class_name = ucc(file_id) %>
<pre><code class="ruby">data = <%= class_name %>.from_file("path/to/local/file.<%= meta['file-extension'] || format_name %>")</code></pre>
<%= code cur_lang, <<-CODE
data = #{ class_name }.from_file("path/to/local/file.#{ meta['file-extension'] || format_name }")
CODE
%>

<p>Or parse structure from a string of bytes:</p>

<pre><code class="ruby">bytes = "\x00\x01\x02..."
data = <%= class_name %>.new(Kaitai::Struct::Stream.new(bytes))</code></pre>
<%= code cur_lang, <<-CODE
bytes = "\\x00\\x01\\x02..."
data = #{ class_name }.new(Kaitai::Struct::Stream.new(bytes))
CODE
%>

<p>After that, one can get various attributes from the structure by invoking getter methods like:</p>

<pre><code class="ruby"><% usage_attrs.each { |attr| %>data.<%= attr[:name] %> # => <%= attr[:doc] %><% } %></code></pre>
<% src_usage_attrs = ""
usage_attrs.each { |attr|
src_usage_attrs += <<-CODE
data.#{ attr[:name] } # => #{ attr[:doc] }
CODE
}
%>
<%= code cur_lang, src_usage_attrs %>

0 comments on commit 4b5381c

Please sign in to comment.