sinatra-fuzzy_layout 0.0.3 → 0.0.5
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 +4 -4
- data/lib/sinatra/core_ext/array.rb +5 -0
- data/lib/sinatra/core_ext/regexp.rb +7 -0
- data/lib/sinatra/core_ext/string.rb +6 -0
- data/lib/sinatra/core_ext/symbol.rb +6 -0
- data/lib/sinatra/fuzzy_layout.rb +84 -28
- data/spec/sample_app.rb +1 -1
- data/spec/sample_app_multiple.rb +1 -1
- metadata +33 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59c79a758df3a89091e7651f882fb7c33e4493e5
|
4
|
+
data.tar.gz: b0250e34e0f1277847914f6abc8e37a541a40f70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcad67d2e96111669ddb8c029449edac0d09371f09e9b537e471ef1af84c6e60bed2ede7b7fdd1364e91ecc75d50f4e03b9fedfafd49138298abc7dbf7047fa0
|
7
|
+
data.tar.gz: 3fc6d4d32e10b6e1e1dcbabe8c5e3e9c99c6de7eaa97bb60bab8d916d9c7b14e21f9bb4c0aca13be2ea8dfee20d89235539cd6da80eb61bdebd73f3d3d652883
|
data/lib/sinatra/fuzzy_layout.rb
CHANGED
@@ -1,37 +1,82 @@
|
|
1
1
|
require "sinatra/base"
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
class Regexp
|
10
|
-
def check(arg)
|
11
|
-
false
|
12
|
-
true if self =~ arg
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class String
|
17
|
-
def check(arg)
|
18
|
-
self === arg.to_s
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
class Symbol
|
24
|
-
def check(arg)
|
25
|
-
self === arg.to_sym
|
26
|
-
end
|
27
|
-
end
|
2
|
+
require_relative "core_ext/string.rb"
|
3
|
+
require_relative "core_ext/regexp.rb"
|
4
|
+
require_relative "core_ext/array.rb"
|
5
|
+
require_relative "core_ext/symbol.rb"
|
28
6
|
|
29
7
|
module Sinatra
|
30
8
|
|
9
|
+
# = Sinatra::FuzzyLayout
|
10
|
+
#
|
11
|
+
# <tt>Sinatra::FuzzyLayout</tt> is an extension to enable or disable
|
12
|
+
# layouts for views with much more control. By default, regular Sinatra
|
13
|
+
# provides two options:
|
14
|
+
# 1. You can specify whether the layout should be enabled/disabled
|
15
|
+
# for all views.
|
16
|
+
# 2. You can specify whether the layout should be enabled/disabled
|
17
|
+
# for an individual route/view.
|
18
|
+
#
|
19
|
+
# This extension provides two DSL methods `enable_layout_for` and
|
20
|
+
# `disable_layout_for` which accept multiple parameters using which you
|
21
|
+
# can have greater control over the layout-ing.
|
22
|
+
#
|
23
|
+
# == Usage
|
24
|
+
#
|
25
|
+
# In your application, you can use the `enable_layout_for` or
|
26
|
+
# `disable_layout_for` DSL methods to specify which route/view should
|
27
|
+
# have the layout and which routes/views should not.
|
28
|
+
#
|
29
|
+
# enable_layout_for :index, :home, /user/
|
30
|
+
#
|
31
|
+
# All views that have the name "index", "home" or any view whose name
|
32
|
+
# matches the regex /user/ will have it's layout disabled.
|
33
|
+
#
|
34
|
+
# disable_layout_for /reports/
|
35
|
+
#
|
36
|
+
# The layout will be disabled for all views that match the regex /reports/
|
37
|
+
# like "user_reports.slim" or "usage_reports.erb"
|
38
|
+
#
|
39
|
+
# === Classic Application
|
40
|
+
#
|
41
|
+
# To use the extension in a classic application, all you have to do is
|
42
|
+
# require it.
|
43
|
+
#
|
44
|
+
# require "sinatra"
|
45
|
+
# require "sinatra/fuzzy_layout"
|
46
|
+
#
|
47
|
+
# enable_layout_for :index, :home, /user/
|
48
|
+
# disable_layout_for /reports/
|
49
|
+
#
|
50
|
+
# # rest of the application goes here
|
51
|
+
#
|
52
|
+
# === Modular Application
|
53
|
+
#
|
54
|
+
# To use this in a modular application, you need to `register` the
|
55
|
+
# extension like so:
|
56
|
+
#
|
57
|
+
# require "sinatra/base"
|
58
|
+
# require "sinatra/fuzzy_layout"
|
59
|
+
#
|
60
|
+
# class App < Sinatra::Base
|
61
|
+
# register Sinatra::FuzzyLayout
|
62
|
+
#
|
63
|
+
# enable_layout_for :one, :two, :three
|
64
|
+
#
|
65
|
+
# # rest of the application goes here
|
66
|
+
# end
|
67
|
+
#
|
31
68
|
module FuzzyLayout
|
32
69
|
|
70
|
+
# This module is a placeholder for the non-DSL methods. To know more
|
71
|
+
# about extending Sinatra or how the various bindings/encapsulation
|
72
|
+
# works, refer to [this material on the topic](http://www.sinatrarb.com/extensions.html)
|
73
|
+
#
|
74
|
+
# This module gets included inside the Sinatra::Base class within the
|
75
|
+
# call to `app.helpers TemplatesHelpers`. So we use the class hierarchy
|
76
|
+
# to our advantage and override the `render` method to obtain the name
|
77
|
+
# of the view and other options based on the name of the view.
|
78
|
+
|
33
79
|
module TemplatesHelpers
|
34
|
-
include Sinatra::Templates
|
35
80
|
|
36
81
|
def render(engine, data, options = {}, locals = {}, &block)
|
37
82
|
options = get_new_options_and_template(options, data)
|
@@ -40,6 +85,17 @@ module Sinatra
|
|
40
85
|
|
41
86
|
private
|
42
87
|
|
88
|
+
|
89
|
+
# Sets the layout option for a particular view template.
|
90
|
+
#
|
91
|
+
# == Parameters
|
92
|
+
# options::
|
93
|
+
# A hash of options generated by the app based on the settings
|
94
|
+
# by the user.
|
95
|
+
#
|
96
|
+
# template::
|
97
|
+
# A Symbol representing the name of the view. For example, `:index`
|
98
|
+
|
43
99
|
def get_new_options_and_template(options, template)
|
44
100
|
if settings.enable_list.has_the_template?(template)
|
45
101
|
options[:layout] = true
|
@@ -60,7 +116,7 @@ module Sinatra
|
|
60
116
|
end
|
61
117
|
|
62
118
|
def self.registered(app)
|
63
|
-
app.helpers
|
119
|
+
app.helpers TemplatesHelpers
|
64
120
|
end
|
65
121
|
end
|
66
122
|
|
data/spec/sample_app.rb
CHANGED
data/spec/sample_app_multiple.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-fuzzy_layout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kashyap
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,38 +28,56 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 10.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 10.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '2.6'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- -
|
52
|
+
- - ~>
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '2.6'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: sinatra
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- -
|
59
|
+
- - ~>
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '1.3'
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- -
|
66
|
+
- - ~>
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '1.3'
|
55
69
|
description: "Provides ability to enable or disable layouts \n for
|
56
|
-
templates via Regex"
|
70
|
+
multiple templates via Regex"
|
57
71
|
email:
|
58
72
|
- kashyap.kmbc@gmail.com
|
59
73
|
executables: []
|
60
74
|
extensions: []
|
61
75
|
extra_rdoc_files: []
|
62
76
|
files:
|
77
|
+
- lib/sinatra/core_ext/array.rb
|
78
|
+
- lib/sinatra/core_ext/regexp.rb
|
79
|
+
- lib/sinatra/core_ext/string.rb
|
80
|
+
- lib/sinatra/core_ext/symbol.rb
|
63
81
|
- lib/sinatra/fuzzy_layout.rb
|
64
82
|
- Rakefile
|
65
83
|
- README.md
|
@@ -93,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
111
|
requirements:
|
94
112
|
- - '>='
|
95
113
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
114
|
+
version: 1.9.3
|
97
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
116
|
requirements:
|
99
117
|
- - '>='
|
@@ -105,9 +123,9 @@ rubygems_version: 2.0.3
|
|
105
123
|
signing_key:
|
106
124
|
specification_version: 4
|
107
125
|
summary: In Sinatra, the user can disable the layout template either globally or
|
108
|
-
on a per template basis in the individual routes. This
|
109
|
-
to enable or disable the layout rendering based on Regex description. Refer
|
110
|
-
Readme for more details
|
126
|
+
on a per template basis in the individual routes. This extension will provide
|
127
|
+
support to enable or disable the layout rendering based on Regex description. Refer
|
128
|
+
to Readme for more details
|
111
129
|
test_files:
|
112
130
|
- spec/fuzzy_layout_spec.rb
|
113
131
|
- spec/sample_app.rb
|