x_ray 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1bfbbb0efb83ed74530d2ce5e4d57ffc1d2d239b
4
- data.tar.gz: 197b09fbb571beec222a2d449998b5c7523f5cad
3
+ metadata.gz: b09379710fafd39bbb50c68ae70273678502e80e
4
+ data.tar.gz: b15360848d164861247f4864bfc5a24d6622f391
5
5
  SHA512:
6
- metadata.gz: ad831d894011b81e0924dbd23d08cac4668a8f7d05656df81d65d3f3cbfd85f6840b31d0ee918f92388bac8751b5e6120c77e2114bceb5f4389cc1e438558638
7
- data.tar.gz: f34a40cf5155eddbe82aa4e4fc3abdf1255b476f51e989850cb732f1503ba071f22ff2ce3ed1ba29f4755a960fa596434a2066c96ff7872620914d8bea7eb2b9
6
+ metadata.gz: 5808c572bb76b92b00a07bf3caed25c06b90c21a8701a526d8ef342dcf5ceb5e1ac3c7e736fa52183aed33c502b185e3c1d5dde3ea25651414d3feefec22c914
7
+ data.tar.gz: c8e1e424c5dbf198e6b5022dc21c21398669652972ac3f89aafbb8dc581916f67a09d771f39e6651c77f266c6dfb8effccfc52e525b186afc6a57294bb624886
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # x_ray
2
2
 
3
- x_ray is a gem that helps easily display code examples, supports plain HTML and ERB.
3
+ x_ray is a gem that helps easily display code examples, supports plain HTML and ERB. A lightweight tool for establishing your style guide.
4
4
 
5
5
  ## Installation
6
6
 
@@ -24,34 +24,71 @@ include XRay::Helper
24
24
 
25
25
  ## Usage
26
26
 
27
+ Show HTML example:
27
28
  ```erb
28
- <!-- Render HTML from HTML -->
29
29
  <%= x_ray do %>
30
30
  <ol>
31
31
  <li>First thing</li>
32
32
  <li>Second thing</li>
33
33
  </ol>
34
34
  <% end %>
35
+ ```
36
+ <img src="http://i.imgur.com/og5zaFx.png">
35
37
 
36
- <!-- Render HTML from ERB -->
38
+ Show HTML example using ERB:
39
+ ```erb
37
40
  <%= x_ray do %>
38
41
  <%= submit_tag 'Set Time Zone', class: 'button button-primary' %>
39
42
  <% end %>
43
+ ```
44
+ <img src="http://i.imgur.com/J0P4CIc.png">
40
45
 
41
- <!-- Render ERB from ERB -->
42
- <%= x_ray_erb do %>
43
- &lt;%= submit_tag 'Set Time Zone', class: 'button button-primary' %&gt;
44
- <% end %>
46
+ Show ERB example:
47
+ ```erb
48
+ <%= x_ray_erb(
49
+ <<-ERB
50
+ \<%= submit_tag 'Set Time Zone', class: 'button button-primary' %\>
51
+ ERB
52
+ ) %>
53
+ ```
54
+ <img src="http://i.imgur.com/MszQnBz.png">
45
55
 
46
- <!-- Render ERB from ERB for `render` (inserting ERB with block requires one-off logic) -->
47
- <%= x_ray_erb_render(layout: 'components/collapsable', locals: { heading: 'My virtual training plan'}) do %>
56
+ Show ERB example that inserts with a block. Due to ERB/Rails wonkiness, the ability to use `<%=` with a block is actually a hack (http://stackoverflow.com/questions/17374274/why-is-this-an-error-with-erb); so a hack was necessary to make this to work with `x_ray`. Note: passing ERB into the `<%=` block will not render the block in the "code scan" properly, please use `x_ray_manual` for this case.
57
+ ```erb
58
+ <%= x_ray_erb_insert_with_block(:render, layout: 'components/collapsable', locals: { heading: 'My virtual training plan'}) do %>
48
59
  <div class="box-small">
49
60
  <p class="outer-box-none">look at all this fun stuff in here!</p>
50
61
  </div>
51
62
  <% end %>
63
+
64
+ <%= x_ray_erb_insert_with_block(:form_tag, 'users') do %>
65
+ <%= submit_tag 'Save' %>
66
+ <% end %>
52
67
  ```
68
+ <img src="http://i.imgur.com/zEthweg.png">
53
69
 
54
- <img src="http://i.imgur.com/X1QeI6M.png">
70
+ Show ERB example manually. For all the nitty gritty corner cases, you can use this:
71
+ ```erb
72
+ <%= x_ray_manual(
73
+ <<-ERB
74
+ \<% provide(:body) do %\>
75
+ \<%= render layout: 'components/collapsable', locals: { heading: 'My virtual training plan'} do %\>
76
+ Foo Bar!
77
+ \<% end %\>
78
+ \<% end %\>
79
+ \<%= yield(:body) %\>
80
+ ERB
81
+ ) do %>
82
+ <% provide(:body) do %>
83
+ <%= render layout: 'components/collapsable', locals: { heading: 'My virtual training plan', unique_key: '1sdasd', collapsable: nil} do %>
84
+ Foo Bar!
85
+ <% end %>
86
+ <% end %>
87
+
88
+ <%= yield(:body) %>
89
+ <% end %>
90
+ ```
91
+ <img src="http://i.imgur.com/raa94ap.png">
55
92
 
56
93
  ### Customization
57
94
 
@@ -4,25 +4,20 @@ module XRay
4
4
  render(layout: 'layouts/x_ray/scan', &block)
5
5
  end
6
6
 
7
- def x_ray_erb(&block)
8
- render(layout: 'layouts/x_ray/erb_scan', &block)
7
+ def x_ray_erb(code)
8
+ render(partial: 'layouts/x_ray/erb_scan', locals: { code: code })
9
9
  end
10
10
 
11
- def x_ray_erb_render(context, options={}, &block)
12
- render(partial: 'layouts/x_ray/erb_render_scan', locals: { context: context, options: options, block: block})
11
+ def x_ray_erb_insert_with_block(method, *params, &block)
12
+ example = send(method, *params, &block)
13
+ render(partial: 'layouts/x_ray/erb_insert_with_block_scan', locals: { example: example,method: method, params: params, block: block })
13
14
  end
14
15
 
15
- def x_ray_erb_render_code(context, options, raw_block)
16
- code = if raw_block
17
- "<%= render #{context}, #{options} do %>\n#{x_ray_scan(raw_block)}\n<% end %>"
18
- else
19
- "<%= render #{context}, #{options} %>"
20
- end
21
-
22
- x_ray_scan(code)
16
+ def x_ray_manual(code, &example_block)
17
+ render(partial: 'layouts/x_ray/manual_scan', locals: { example_block: example_block, code: code })
23
18
  end
24
19
 
25
- def x_ray_scan(code)
20
+ def x_ray_output_code(code)
26
21
  text = <<-HTML.strip_heredoc
27
22
  #{code}
28
23
  HTML
@@ -0,0 +1,18 @@
1
+ <div class="x-ray-block">
2
+ <div class="example">
3
+ <%= example %>
4
+ </div>
5
+
6
+ <div class="code-scan">
7
+ <div hidden>
8
+ <% block_code = <<-HTML.strip_heredoc
9
+ #{block.call}
10
+ HTML
11
+ %>
12
+ </div>
13
+ <pre>
14
+ <% params_string = params.map{ |param| param.is_a?(String) ? "'#{param}'" : param }.join(', ') %>
15
+ <%= "\<%= #{method.to_s} #{params_string} do %\>#{block_code.split("\n").join("\n ")}\n\<% end %\>" %>
16
+ </pre>
17
+ </div>
18
+ </div>
@@ -1,11 +1,11 @@
1
1
  <div class="x-ray-block">
2
2
  <div class="example">
3
- <%= ERB.new(yield.gsub('&lt;', '<').gsub('&gt;', '>')).result(binding).html_safe %>
3
+ <%= ERB.new(code).result(binding).html_safe %>
4
4
  </div>
5
5
 
6
6
  <div class="code-scan">
7
7
  <pre>
8
- <%= x_ray_scan(yield.gsub('&lt;', '<').gsub('&gt;', '>')) %>
8
+ <%= x_ray_output_code(code) %>
9
9
  </pre>
10
10
  </div>
11
11
  </div>
@@ -0,0 +1,11 @@
1
+ <div class="x-ray-block">
2
+ <div class="example">
3
+ <%= example_block.call %>
4
+ </div>
5
+
6
+ <div class="code-scan">
7
+ <pre>
8
+ <%= x_ray_output_code(code) %>
9
+ </pre>
10
+ </div>
11
+ </div>
@@ -5,7 +5,7 @@
5
5
 
6
6
  <div class="code-scan">
7
7
  <pre>
8
- <%= x_ray_scan(yield) %>
8
+ <%= x_ray_output_code(yield) %>
9
9
  </pre>
10
10
  </div>
11
11
  </div>
data/lib/x_ray/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module XRay
2
- VERSION = '0.0.9'.freeze
2
+ VERSION = '0.0.10'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: x_ray
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiffany Huang
@@ -51,8 +51,9 @@ files:
51
51
  - app/assets/javascripts/x_ray/application.js
52
52
  - app/assets/stylesheets/x_ray/prettifier.scss
53
53
  - app/helpers/x_ray/helper.rb
54
- - app/views/layouts/x_ray/_erb_render_scan.html.erb
54
+ - app/views/layouts/x_ray/_erb_insert_with_block_scan.erb
55
55
  - app/views/layouts/x_ray/_erb_scan.html.erb
56
+ - app/views/layouts/x_ray/_manual_scan.html.erb
56
57
  - app/views/layouts/x_ray/_scan.html.erb
57
58
  - lib/x_ray.rb
58
59
  - lib/x_ray/engine.rb
@@ -1,12 +0,0 @@
1
- <div class="x-ray-block">
2
- <div class="example">
3
- <%= render(context, options, &block) %>
4
- </div>
5
-
6
- <div class="code-scan">
7
- <pre>
8
- <div hidden><% raw_block = block.try(:call) %></div>
9
- <%= x_ray_erb_render_code(context, options, raw_block) %>
10
- </pre>
11
- </div>
12
- </div>