end_view 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f3054dbb6674965ce22fdfeba1ecd14b6135299
4
- data.tar.gz: 303127059c06331b85b75274e6362cadcae3e360
3
+ metadata.gz: 13f724862bcef543e1ca3548cd79e9ede0210500
4
+ data.tar.gz: 2711de7e149ee22d53f4837329d8ec84221dc445
5
5
  SHA512:
6
- metadata.gz: 3b179876261d57e25381eabbe1ab7be6d86599309542383e818c482ffe7bee2e0f0e61aac6513fff26b467e34b7b0ce295c7b140984142ca52922f974799d47d
7
- data.tar.gz: 2ce08b9f83504d1d74b2734d790498337c26186571076362602d98cb2d109df6d8d223de4a28c0d6887786d48d4b70af70fee23b50894dfc11c9ff72aa222d68
6
+ metadata.gz: 56e62c0c920d3598df45cdfcf46f13d73e94820dc4b1caa3c87317ba9154dcfe012634900cdc9914fcf5aaf619b483601f54a3fb094eaf24ce58f30385eef805
7
+ data.tar.gz: 65097ea3bbb3c75ccbb88fb5314e1fbc6d396a534b73f54ac20a7ca7624e07579e9afafa38e75ac2c949ed94b09b285b77415394f24fa39acee644bf3568941c
@@ -3,6 +3,10 @@ require 'attire'
3
3
  require 'inflecto'
4
4
 
5
5
  module EndView
6
+ def self.bootstrap_form_group(*args)
7
+ Bootstrap::FormGroup.render(*args)
8
+ end
9
+
6
10
  module Bootstrap
7
11
  class FormGroup
8
12
  include EndView.new(__FILE__)
@@ -66,6 +70,7 @@ end
66
70
 
67
71
  __END__
68
72
 
73
+ / Bootstrap Form Group
69
74
  .form-group
70
75
  - if label
71
76
  %label{label_opts}= label
@@ -1,24 +1,47 @@
1
1
  require 'end_view/bootstrap/modal'
2
- require 'forwardable'
3
2
 
4
3
  module EndView
4
+ def self.bootstrap_form_modal(*args, &b)
5
+ Bootstrap::FormModal.render(*args, &b)
6
+ end
7
+
5
8
  module Bootstrap
6
- class FormModal < Modal
7
- compile(__FILE__)
8
- extend Forwardable
9
+ class FormModal
10
+ include EndView.new(__FILE__)
11
+
12
+ def self.render(*args, &b)
13
+ new(*args).render(&b)
14
+ end
9
15
 
10
- def initialize(form_builder, opts = {})
11
- super({ dismiss_value: 'Cancel' }.merge(opts))
12
- @form_builder = form_builder
13
- @submit_value = opts[:submit_value] || 'Okay'
16
+ attr_init :id, :form_builder, :'opts = {}'
17
+
18
+ def render(*args, &b)
19
+ super(*args) { Modal.render(id, opts_with_buttons, &b) }
14
20
  end
15
21
 
16
22
  private
17
23
 
18
- attr_reader :form_builder, :submit_value
19
- def_delegators :form_builder, :form_opts,
20
- :authenticity_token_opts,
21
- :form_method_opts
24
+ alias_method :f, :form_builder
25
+
26
+ def opts_with_buttons
27
+ { buttons: buttons }.merge(@opts)
28
+ end
29
+
30
+ def cancel_value
31
+ opts[:cancel_value] || 'Cancel'
32
+ end
33
+
34
+ def submit_value
35
+ opts[:submit_value] || 'Okay'
36
+ end
37
+
38
+ def buttons
39
+ [[cancel_opts, cancel_value], [submit_opts, submit_value]]
40
+ end
41
+
42
+ def cancel_opts
43
+ { class: 'btn btn-default', 'data-dismiss' => :modal }
44
+ end
22
45
 
23
46
  def submit_opts
24
47
  { class: 'btn btn-primary', type: 'submit' }
@@ -29,18 +52,8 @@ end
29
52
 
30
53
  __END__
31
54
 
32
- .modal{modal_opts}
33
- .modal-dialog{dialog_opts}
34
- .modal-content
35
- - if title
36
- .modal-header
37
- %button{close_opts}
38
- %span(aria-hidden) &times;
39
- %h4{title_opts}= title
40
- %form{form_opts}
41
- %input{authenticity_token_opts}
42
- %input{form_method_opts}
43
- .modal-body= yield
44
- .modal-footer
45
- %button{dismiss_opts}= dismiss_value
46
- %button{submit_opts}= submit_value
55
+ / Bootstrap Form Modal
56
+ %form{f.form_opts}
57
+ %input{f.auth_token_opts}
58
+ %input{f.form_method_opts}
59
+ = yield
@@ -2,31 +2,37 @@ require 'end_view'
2
2
  require 'attire'
3
3
 
4
4
  module EndView
5
+ def self.bootstrap_modal(*args, &b)
6
+ Bootstrap::Modal.render(*args, &b)
7
+ end
8
+
5
9
  module Bootstrap
6
10
  class Modal
7
11
  include EndView.new(__FILE__)
8
- attr_init modal_id: "modal#{rand(10_000)}",
9
- title: nil,
10
- size: nil,
11
- label: "label#{rand(10_000)}",
12
- dismiss_value: 'Okay'
12
+ attr_init :id, title: nil,
13
+ size: nil,
14
+ label: nil,
15
+ dismiss_value: 'Okay',
16
+ buttons: nil
13
17
 
14
18
  def self.render(*args, &b)
15
19
  new(*args).render(&b)
16
20
  end
17
21
 
18
- public :modal_id
19
-
20
22
  private
21
23
 
22
24
  def modal_opts
23
- { id: modal_id,
25
+ { id: id,
24
26
  class: 'fade',
25
27
  tabindex: -1,
26
28
  role: 'dialog',
27
29
  aria: { labelledby: label, hidden: true } }
28
30
  end
29
31
 
32
+ def label
33
+ @label ||= "#{id}Label"
34
+ end
35
+
30
36
  def dialog_opts
31
37
  { class: size }
32
38
  end
@@ -41,6 +47,10 @@ module EndView
41
47
  { class: 'modal-title', id: label }
42
48
  end
43
49
 
50
+ def buttons
51
+ @buttons ||= [[dismiss_opts, dismiss_value]]
52
+ end
53
+
44
54
  def dismiss_opts
45
55
  { class: 'btn btn-default', 'data-dismiss' => :modal }
46
56
  end
@@ -50,14 +60,22 @@ end
50
60
 
51
61
  __END__
52
62
 
63
+ / Bootstrap Modal
53
64
  .modal{modal_opts}
54
65
  .modal-dialog{dialog_opts}
55
66
  .modal-content
67
+
56
68
  - if title
69
+ / Modal Header
57
70
  .modal-header
58
71
  %button{close_opts}
59
72
  %span(aria-hidden) &times;
60
73
  %h4{title_opts}= title
74
+
75
+ / Modal Body
61
76
  .modal-body= yield
77
+
78
+ / Modal Footer
62
79
  .modal-footer
63
- %button{dismiss_opts}= dismiss_value
80
+ - buttons.each do |(button_opts, button_value)|
81
+ %button{button_opts}= button_value
@@ -0,0 +1,38 @@
1
+ require 'end_view'
2
+ require 'attire'
3
+ require 'end_view/bootstrap/form_group'
4
+ require 'end_view/form/record_builder'
5
+
6
+ module EndView
7
+ def self.bootstrap_simple_form(*args)
8
+ Bootstrap::SimpleForm.render(*args)
9
+ end
10
+
11
+ module Bootstrap
12
+ class SimpleForm
13
+ include EndView.new(__FILE__)
14
+ attr_method :render, :url_or_record, :auth_token, :attributes, :'opts = {}'
15
+
16
+ private
17
+
18
+ def form_builder
19
+ @form_builder ||= EndView.form_builder(url_or_record, auth_token, opts)
20
+ end
21
+ alias_method :f, :form_builder
22
+
23
+ def form_group(attribute)
24
+ FormGroup.render(form_builder, attribute)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ __END__
31
+
32
+ / Bootstrap Simple Form
33
+ %form{f.form_opts}
34
+ %input{f.auth_token_opts}
35
+ %input{f.form_method_opts}
36
+ - attributes.each do |attribute|
37
+ = form_group(attribute)
38
+ %button{type: 'submit'} Okay
@@ -0,0 +1,36 @@
1
+ require 'end_view/bootstrap/form_modal'
2
+ require 'end_view/bootstrap/form_group'
3
+ require 'end_view/form'
4
+
5
+ module EndView
6
+ def self.bootstrap_simple_form_modal(*args)
7
+ Bootstrap::SimpleFormModal.render(*args)
8
+ end
9
+
10
+ module Bootstrap
11
+ class SimpleFormModal
12
+ attr_method :render, :id,
13
+ :url_or_record,
14
+ :auth_token,
15
+ :attributes,
16
+ :'form_opts = {}',
17
+ :'modal_opts= {}'
18
+
19
+ def render
20
+ FormModal.render(id, form_builder, modal_opts) do
21
+ attributes.map { |attribute| form_group(attribute) }.join
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def form_builder
28
+ @form_builder ||= EndView.form_builder(url_or_record, auth_token, form_opts)
29
+ end
30
+
31
+ def form_group(attribute)
32
+ FormGroup.render(form_builder, attribute)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ require 'attire'
2
+ require 'inflecto'
3
+
4
+ module EndView
5
+ def self.bootstrap_tab_pane(*args, &b)
6
+ Bootstrap::TabPane.new(*args, &b)
7
+ end
8
+
9
+ module Bootstrap
10
+ class TabPane
11
+ attr_init :id, { content: nil, label: nil }, :'&content_block'
12
+ public :id
13
+ attr_writer :active
14
+
15
+ def render
16
+ content || content_block.call
17
+ end
18
+
19
+ def label
20
+ @label ||= Inflecto.humanize(id)
21
+ end
22
+
23
+ def active
24
+ @active && 'active'
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,64 @@
1
+ require 'end_view'
2
+ require 'attire'
3
+ require 'end_view/bootstrap/tab_pane'
4
+
5
+ module EndView
6
+ def self.bootstrap_tabpanel(*args)
7
+ Bootstrap::Tabpanel.new(*args)
8
+ end
9
+
10
+ module Bootstrap
11
+ class Tabpanel
12
+ include EndView.new(__FILE__)
13
+ attr_init id: nil, panes: [], fade: false, active_pane: 0
14
+ public :panes
15
+
16
+ def add_pane(*args, &b)
17
+ panes << TabPane.new(*args, &b)
18
+ end
19
+
20
+ def render(*args, &b)
21
+ set_active_pane
22
+ super(*args, &b)
23
+ end
24
+
25
+ private
26
+
27
+ def set_active_pane
28
+ panes.each { |p| p.active = false }
29
+ panes[active_pane].active = true
30
+ end
31
+
32
+ def link_opts(pane)
33
+ { href: "##{pane.id}",
34
+ role: 'tab',
35
+ 'aria-controls' => pane.id,
36
+ 'data-toggle' => 'tab' }
37
+ end
38
+
39
+ def pane_opts(pane)
40
+ { id: pane.id,
41
+ role: 'tabpanel',
42
+ class: [fade && 'fade',
43
+ fade && pane.active && 'in',
44
+ pane.active] }
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ __END__
51
+
52
+ / Bootstrap Tabpanel
53
+ %div{id: id, role: 'tabpanel'}
54
+
55
+ / Nav Tabs
56
+ %ul.nav.nav-tabs{role: 'tablist'}
57
+ - panes.each do |pane|
58
+ %li{role: 'presentation', class: pane.active}
59
+ %a{link_opts(pane)}= pane.label
60
+
61
+ / Tab Panes
62
+ .tab-content
63
+ - panes.each do |pane|
64
+ .tab-pane{pane_opts(pane)}= pane.render
@@ -1,4 +1,7 @@
1
1
  require 'end_view/bootstrap/modal'
2
2
  require 'end_view/bootstrap/form_modal'
3
3
  require 'end_view/bootstrap/form_group'
4
- require 'end_view/bootstrap/login_modal'
4
+ require 'end_view/bootstrap/simple_form'
5
+ require 'end_view/bootstrap/simple_form_modal'
6
+ require 'end_view/bootstrap/tab_pane'
7
+ require 'end_view/bootstrap/tabpanel'
@@ -1,18 +1,22 @@
1
1
  require 'attire'
2
2
 
3
3
  module EndView
4
+ def self.form_builder(*args)
5
+ Form::Builder.new(*args)
6
+ end
7
+
4
8
  module Form
5
9
  class Builder
6
- attr_init :form_url, :form_authenticity_token, form_method: 'post'
10
+ attr_init :form_url, :auth_token, form_method: 'post'
7
11
 
8
12
  def form_opts(opts = {})
9
13
  { action: form_url, method: 'post' }.merge(opts)
10
14
  end
11
15
 
12
- def authenticity_token_opts(opts = {})
13
- { name: 'authenticity_token',
16
+ def auth_token_opts(opts = {})
17
+ { name: 'auth_token',
14
18
  type: 'hidden',
15
- value: form_authenticity_token }.merge(opts)
19
+ value: auth_token }.merge(opts)
16
20
  end
17
21
 
18
22
  def form_method_opts(opts = {})
@@ -2,13 +2,18 @@ require 'inflecto'
2
2
  require 'end_view/form/builder'
3
3
 
4
4
  module EndView
5
+ def self.form_builder(url_or_record, *args)
6
+ builder_class = url_or_record.is_a?(String) ? Form::Builder : Form::RecordBuilder
7
+ builder_class.new(url_or_record, *args)
8
+ end
9
+
5
10
  module Form
6
11
  class RecordBuilder < Builder
7
- attr_init :record, :form_authenticity_token, model_name: nil,
8
- model_id: nil,
9
- action: nil,
10
- form_method: nil,
11
- form_url: nil
12
+ attr_init :record, :auth_token, model_name: nil,
13
+ model_id: nil,
14
+ action: nil,
15
+ form_method: nil,
16
+ form_url: nil
12
17
 
13
18
  def form_opts(opts = {})
14
19
  super.merge(class: form_class, id: form_id).merge(opts)
@@ -0,0 +1,39 @@
1
+ require 'end_view'
2
+ require 'inflecto'
3
+ require 'end_view/form/record_builder'
4
+
5
+ module EndView
6
+ def self.simple_form(*args)
7
+ Form::SimpleForm.render(*args)
8
+ end
9
+
10
+ module Form
11
+ class SimpleForm
12
+ include EndView.new(__FILE__)
13
+ attr_method :render, :url_or_record, :auth_token, :attributes, :'opts = {}'
14
+
15
+ private
16
+
17
+ def form_builder
18
+ @form_builder ||= EndView.form_builder(url_or_record, auth_token, opts)
19
+ end
20
+ alias_method :f, :form_builder
21
+
22
+ def label(attribute)
23
+ Inflecto.humanize(attribute.to_s)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ __END__
30
+
31
+ / Simple Form
32
+ %form{f.form_opts}
33
+ %input{f.auth_token_opts}
34
+ %input{f.form_method_opts}
35
+ - attributes.each do |attribute|
36
+ .form-group
37
+ %label{f.label_opts(attribute)}= label(attribute)
38
+ %input{f.input_opts(attribute)}/
39
+ %button{type: 'submit'} Okay
data/lib/end_view/form.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'end_view/form/builder'
2
2
  require 'end_view/form/record_builder'
3
+ require 'end_view/form/simple_form'
@@ -1,23 +1,19 @@
1
1
  require 'end_view'
2
- require 'forwardable'
3
2
  require 'attire'
4
3
 
5
4
  module EndView
5
+ def self.rails_layout(*args)
6
+ Rails::Layout.new(*args)
7
+ end
8
+
6
9
  module Rails
7
10
  class Layout
8
11
  include EndView.new(__FILE__)
9
- extend Forwardable
10
- attr_init :view_context, :title
11
-
12
- def self.render(*args, &b)
13
- new(*args).render(&b)
14
- end
12
+ attr_init :view_context, :title, head: nil
15
13
 
16
14
  private
17
15
 
18
- def_delegators :view_context, :stylesheet_link_tag,
19
- :javascript_include_tag,
20
- :csrf_meta_tags
16
+ alias_method :vc, :view_context
21
17
 
22
18
  def stylesheet_args
23
19
  ['application', { media: 'all', 'data-turbolinks-track' => true }]
@@ -36,7 +32,8 @@ __END__
36
32
  %html
37
33
  %head
38
34
  %title= title
39
- = stylesheet_link_tag(*stylesheet_args)
40
- = javascript_include_tag(*javascript_args)
41
- = csrf_meta_tags
35
+ = vc.stylesheet_link_tag(*stylesheet_args)
36
+ = vc.javascript_include_tag(*javascript_args)
37
+ = vc.csrf_meta_tags
38
+ = head
42
39
  %body= yield
data/lib/end_view.rb CHANGED
@@ -9,7 +9,7 @@ module EndView
9
9
  @default_engine ||= Tilt::HamlTemplate
10
10
  end
11
11
 
12
- def new(file, template_engine = EndView.default_engine)
12
+ def new(file, template_engine = default_engine)
13
13
  Module.new do
14
14
  define_singleton_method(:included) do |base|
15
15
  base.extend ClassMethods
@@ -29,21 +29,17 @@ module EndView
29
29
 
30
30
  module ClassMethods
31
31
  def inherited(child)
32
+ super
32
33
  child.template = template
33
34
  child.layout = layout
34
35
  end
35
36
 
36
37
  def compile(file, template_engine = EndView.default_engine)
37
- @template = template_engine.new { data(file) }
38
+ data = IO.read(file).gsub("\r\n", "\n").split(/^__END__$/).last
39
+ @template = template_engine.new(file) { data }
38
40
  end
39
41
 
40
42
  attr_accessor :layout, :template
41
-
42
- private
43
-
44
- def data(file)
45
- IO.read(file).gsub("\r\n", "\n").split(/^__END__$/)[1]
46
- end
47
43
  end
48
44
 
49
45
  module Methods
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: end_view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max White
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-09 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tilt
@@ -47,7 +47,7 @@ dependencies:
47
47
  version: '0.1'
48
48
  - - '>='
49
49
  - !ruby/object:Gem::Version
50
- version: 0.1.1
50
+ version: 0.1.3
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -57,7 +57,7 @@ dependencies:
57
57
  version: '0.1'
58
58
  - - '>='
59
59
  - !ruby/object:Gem::Version
60
- version: 0.1.1
60
+ version: 0.1.3
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: inflecto
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -130,11 +130,15 @@ files:
130
130
  - lib/end_view/bootstrap.rb
131
131
  - lib/end_view/bootstrap/form_group.rb
132
132
  - lib/end_view/bootstrap/form_modal.rb
133
- - lib/end_view/bootstrap/login_modal.rb
134
133
  - lib/end_view/bootstrap/modal.rb
134
+ - lib/end_view/bootstrap/simple_form.rb
135
+ - lib/end_view/bootstrap/simple_form_modal.rb
136
+ - lib/end_view/bootstrap/tab_pane.rb
137
+ - lib/end_view/bootstrap/tabpanel.rb
135
138
  - lib/end_view/form.rb
136
139
  - lib/end_view/form/builder.rb
137
140
  - lib/end_view/form/record_builder.rb
141
+ - lib/end_view/form/simple_form.rb
138
142
  - lib/end_view/rails.rb
139
143
  - lib/end_view/rails/layout.rb
140
144
  homepage: https://github.com/mushishi78/end_view
@@ -1,30 +0,0 @@
1
- require 'end_view/bootstrap/form_modal'
2
- require 'end_view/bootstrap/form_group'
3
- require 'end_view/form/record_builder'
4
-
5
- module EndView
6
- module Bootstrap
7
- class LoginModal
8
- attr_method :render, :user, :form_authenticty_token, form_opts: {},
9
- modal_opts: {},
10
- form_builder: nil
11
-
12
- def render
13
- FormModal.render(form_builder, modal_opts) do
14
- form_group(:email) << form_group(:password)
15
- end
16
- end
17
-
18
- private
19
-
20
- def form_builder
21
- @form_builder ||=
22
- Form::RecordBuilder.new(user, form_authenticty_token, form_opts)
23
- end
24
-
25
- def form_group(attribute)
26
- FormGroup.render(form_builder, attribute)
27
- end
28
- end
29
- end
30
- end