bard_static 1.4.3 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,31 +5,23 @@ module BardStatic
5
5
 
6
6
  def mockups
7
7
  env["bard_static.prototype"] = true
8
- with_404_handler { render_with_index "mockups/#{params[:file_path]}", :layout => false }
8
+ render_with_index "mockups/#{params[:file_path]}", :layout => false
9
9
  end
10
10
 
11
11
  def static
12
12
  layout = !request.xhr? # render ajax responses with no layout
13
- with_404_handler { render_with_index "static/#{params[:file_path]}", :layout => layout }
13
+ render_with_index "static/#{params[:file_path]}", :layout => layout
14
14
  end
15
15
 
16
16
  private
17
17
 
18
- def with_404_handler
19
- begin
20
- yield
21
- rescue ActionView::MissingTemplate
22
- render :text => "Not Found", :status => 404
23
- end
24
- end
25
-
26
18
  def render_with_index path, options = {}
27
19
  begin
28
20
  options = options.dup # render is destructive to the options hash!
29
- options = options.merge(:partial => path)
21
+ options = options.merge(:template => path)
30
22
  render options
31
23
  rescue ActionView::MissingTemplate
32
- options[:partial] = "#{path}/index"
24
+ options[:template] = "#{path}/index"
33
25
  render options
34
26
  end
35
27
  end
@@ -0,0 +1,8 @@
1
+ module BardStatic
2
+ module LayoutHelper
3
+ def layout layout, &block
4
+ render text: capture(&block), layout: "layouts/#{layout}"
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,91 @@
1
+ module BardStatic
2
+ module LinkToHelper
3
+ def link_to(*args, &block)
4
+ args.unshift capture(&block) if block_given?
5
+ LinkTo.render(self, *args)
6
+ end
7
+
8
+ def link_to_current(*args, &block)
9
+ args.unshift capture(&block) if block_given?
10
+ LinkToCurrent.render(self, *args) do |link|
11
+ link.current_path = request.fullpath
12
+ end.render
13
+ end
14
+
15
+ def link_to_nav(*args, &block)
16
+ args.unshift capture(&block) if block_given?
17
+ LinkToNav.render(self, *args) do |link|
18
+ link.current_path = request.fullpath
19
+ end
20
+ end
21
+
22
+ class LinkTo
23
+ def self.render *args, &block
24
+ if block_given?
25
+ new(*args, &block).render
26
+ else
27
+ new(*args).render
28
+ end
29
+ end
30
+
31
+ def initialize context, name, options = {}, html_options = {}, &block
32
+ @context = context
33
+ @name = name
34
+ @options = options || {}
35
+ @html_options = html_options
36
+ @html_options = @context.send(:convert_options_to_data_attributes, @options, @html_options)
37
+ yield self if block_given?
38
+ end
39
+
40
+ def render
41
+ "<a #{href_attr}#{tag_options}>#{body}</a>".html_safe
42
+ end
43
+
44
+ attr_reader :context, :name, :options, :html_options
45
+
46
+ def url
47
+ context.url_for(options)
48
+ end
49
+
50
+ private
51
+
52
+ def href_attr
53
+ "href=\"#{ERB::Util.html_escape(url)}\"" unless html_options["href"]
54
+ end
55
+
56
+ def tag_options
57
+ context.send(:tag_options, html_options)
58
+ end
59
+
60
+ def body
61
+ ERB::Util.html_escape(name || url)
62
+ end
63
+ end
64
+
65
+ class LinkToCurrent < LinkTo
66
+ attr_accessor :current_path
67
+
68
+ def add_class class_name
69
+ html_options[:class] ||= ""
70
+ html_options[:class] << " #{class_name}"
71
+ html_options[:class].strip!
72
+ end
73
+
74
+ def render
75
+ add_class("current") if current_condition
76
+ super
77
+ end
78
+
79
+ def current_condition
80
+ html_options.delete(:if) || url == current_path
81
+ end
82
+ end
83
+
84
+ class LinkToNav < LinkToCurrent
85
+ def current_condition
86
+ super || url.starts_with?(current_path)
87
+ end
88
+ end
89
+ end
90
+ end
91
+
data/config/routes.rb CHANGED
@@ -3,6 +3,6 @@ Rails.application.routes.draw do
3
3
  root :to => "static#mockups", :file_path => "index"
4
4
  get "/*file_path" => "static#mockups"
5
5
  end
6
- root :to => "bard_static/static#static", :file_path => "index"
6
+ root :to => "bard_static/static#static", :file_path => "index", :as => "bard_static_default_root"
7
7
  get "*file_path" => "bard_static/static#static"
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module BardStatic
2
- VERSION = "1.4.3"
2
+ VERSION = "1.5.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard_static
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 4
9
- - 3
10
- version: 1.4.3
8
+ - 5
9
+ - 0
10
+ version: 1.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Micah Geisel
@@ -21,7 +21,7 @@ autorequire:
21
21
  bindir: bin
22
22
  cert_chain: []
23
23
 
24
- date: 2013-06-12 00:00:00 Z
24
+ date: 2013-06-23 00:00:00 Z
25
25
  dependencies: []
26
26
 
27
27
  description: Handcrafted prototypes for Rails.
@@ -36,6 +36,8 @@ extra_rdoc_files: []
36
36
  files:
37
37
  - app/controllers/bard_static/static_controller.rb
38
38
  - app/views/static/error.html.haml
39
+ - app/helpers/bard_static/link_to_helper.rb
40
+ - app/helpers/bard_static/layout_helper.rb
39
41
  - lib/bard_static/version.rb
40
42
  - lib/bard_static/no_robots_middleware.rb
41
43
  - lib/bard_static.rb