blocky 0.0.3 → 0.0.4

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: 3b4a633bced0c43db6ac323af8492cf79c4c21da
4
- data.tar.gz: 7025083b245e261e6ee8e97746fac325c0260183
3
+ metadata.gz: a2b133372cdb42fddfcde315ee3cf807c07f09ed
4
+ data.tar.gz: b0e2b556c60553e2237ec40366e8c4748dbae848
5
5
  SHA512:
6
- metadata.gz: bf0b9c68fa1ed224be3aa72c0a1e8527fcf5cf27151a55d8029f8b85f98d9ed6d790b6b97cabfe158be50d39ae3262b54edc3d5eb435a1930f839b33be4e9d65
7
- data.tar.gz: 4a0c368eca9a0c4110d347b97dc183c175168977e34f3073e74dd2cc27eda715306f46ac50b548dcb1f9f7684cf3796ee5446f0af1b2197963f73f02c27aafed
6
+ metadata.gz: 985a2a51f3473ecfa5afbc6644b896a0a4e1281dc5241e7e8bc28dc1c85fc6b3d84316e4c623c2ecae811b30d1ca25254153c2db3c2d3b14e96e5616a99cdf3c
7
+ data.tar.gz: b3aa84a7cf0af11e0f977e8a21ef29226b3e000817548baf74fe510a4b49c74e99732f4660b44215aa135236f346d9678a384ed6693a368c302b3faed2b08725
data/README.md CHANGED
@@ -52,6 +52,14 @@ TODO: Add example for limiting access to admin users.
52
52
 
53
53
  ## Usage
54
54
 
55
+ Include `BlockyHelper` in your `ApplicationHelper`:
56
+
57
+ ```ruby
58
+ module ApplicationHelper
59
+ include BlockyHelper
60
+ end
61
+ ```
62
+
55
63
  To create a content block, simply use the `blocky` helper
56
64
  and specify a content key in any ERB template:
57
65
 
@@ -1,12 +1,10 @@
1
1
  module BlockyHelper
2
2
 
3
3
  def blocky(block_name, options={})
4
- controller_name = options[:global] ? nil : controller.controller_name
5
- action_name = options[:global] ? nil : controller.action_name
4
+ page_path = options[:global] ? nil : request.fullpath
6
5
 
7
6
  content_block = Blocky::ContentBlock.where({
8
- controller: controller_name,
9
- action: action_name,
7
+ page_path: page_path,
10
8
  name: block_name
11
9
  }).first_or_create
12
10
 
@@ -2,15 +2,16 @@ module Blocky
2
2
  class ContentBlock < ActiveRecord::Base
3
3
  before_save :tidy_content
4
4
 
5
- scope :global, -> { where("controller IS NULL AND action IS NULL") }
6
- scope :per_page, -> { where("controller IS NOT NULL AND action IS NOT NULL") }
5
+ scope :global, -> { where("page_path IS NULL") }
6
+ scope :per_page, -> { where("page_path IS NOT NULL") }
7
7
 
8
8
  def global?
9
- self.controller.nil? && self.action.nil?
9
+ self.page_path.nil?
10
10
  end
11
11
 
12
12
  def tidy_content
13
13
  tidy = Tidy.new({
14
+ char_encoding: "raw",
14
15
  doctype: "omit",
15
16
  indent: "auto",
16
17
  indent_spaces: 2,
@@ -20,7 +21,8 @@ module Blocky
20
21
  tab_size: 2,
21
22
  tidy_mark: false
22
23
  })
23
- self.content = tidy.clean(self.content.strip)
24
+ html = tidy.clean(self.content.to_s.strip)
25
+ self.content = "\n" + (html.blank? ? "<p><br/></p>" : html) + "\n"
24
26
  end
25
27
 
26
28
  end
@@ -25,15 +25,12 @@
25
25
  </td>
26
26
  </tr>
27
27
  <% end %>
28
- <% @content_blocks.group_by{|content_block| [content_block.controller, content_block.action] }.each do |group, content_blocks| %>
28
+ <% @content_blocks.group_by{|content_block| content_block.page_path }.each do |page_path, content_blocks| %>
29
29
  <% content_blocks.each_with_index do |content_block, index| %>
30
-
31
- <% page_url = main_app.url_for(controller: "/#{group[0]}", action: group[1], only_path: true) %>
32
-
33
30
  <tr class="per-page <%= index == 0 ? 'page-start' : '' %>">
34
31
  <td class="page">
35
32
  <% if index == 0 %>
36
- <%= link_to page_url, page_url, target: "_blank" %>
33
+ <%= link_to page_path, page_path, target: "_blank" %>
37
34
  <% end %>
38
35
  </td>
39
36
  <td>
@@ -0,0 +1,7 @@
1
+ class AddPagePathToContentBlocks < ActiveRecord::Migration
2
+ def change
3
+ add_column :blocky_content_blocks, :page_path, :string
4
+ remove_column :blocky_content_blocks, :controller
5
+ remove_column :blocky_content_blocks, :action
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Blocky
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blocky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Pattison
@@ -344,6 +344,7 @@ files:
344
344
  - config/jshint.json
345
345
  - config/routes.rb
346
346
  - db/migrate/20140326210255_create_blocky_content_blocks.rb
347
+ - db/migrate/20140520212037_add_page_path_to_content_blocks.rb
347
348
  - lib/blocky.rb
348
349
  - lib/blocky/engine.rb
349
350
  - lib/blocky/version.rb