interview 0.0.11 → 0.1.0

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/interview/install/templates/interview.js.coffee +1 -1
  3. data/lib/interview/actionbar.rb +4 -3
  4. data/lib/interview/attribute.rb +3 -3
  5. data/lib/interview/boolean_attribute.rb +4 -4
  6. data/lib/interview/breadcrumbs.rb +2 -2
  7. data/lib/interview/builder.rb +49 -0
  8. data/lib/interview/collapse_container.rb +4 -4
  9. data/lib/interview/condition_container.rb +1 -1
  10. data/lib/interview/container.rb +13 -0
  11. data/lib/interview/container_attribute.rb +2 -2
  12. data/lib/interview/control.rb +0 -16
  13. data/lib/interview/dropdown.rb +2 -2
  14. data/lib/interview/form.rb +2 -2
  15. data/lib/interview/form_errors.rb +1 -1
  16. data/lib/interview/grid.rb +4 -3
  17. data/lib/interview/has_controls.rb +7 -10
  18. data/lib/interview/html_control.rb +7 -1
  19. data/lib/interview/image_attribute.rb +2 -2
  20. data/lib/interview/image_gallery_attribute.rb +2 -2
  21. data/lib/interview/image_light_box.rb +1 -1
  22. data/lib/interview/link.rb +5 -4
  23. data/lib/interview/list.rb +2 -2
  24. data/lib/interview/media_object.rb +6 -5
  25. data/lib/interview/navigation.rb +2 -2
  26. data/lib/interview/navigation_item.rb +2 -2
  27. data/lib/interview/navigation_item_old.rb +2 -2
  28. data/lib/interview/nested_form.rb +3 -3
  29. data/lib/interview/nested_form_add_images.rb +2 -2
  30. data/lib/interview/nested_form_add_link.rb +2 -2
  31. data/lib/interview/nested_form_remove_link.rb +1 -1
  32. data/lib/interview/object_context.rb +5 -1
  33. data/lib/interview/option_attribute.rb +1 -1
  34. data/lib/interview/panel.rb +2 -2
  35. data/lib/interview/polymorphic_add_link.rb +1 -1
  36. data/lib/interview/progress_bar.rb +1 -1
  37. data/lib/interview/search_form.rb +1 -1
  38. data/lib/interview/space.rb +1 -1
  39. data/lib/interview/tab.rb +2 -2
  40. data/lib/interview/tab_box.rb +6 -5
  41. data/lib/interview/text.rb +3 -3
  42. data/lib/interview/tooltip.rb +1 -1
  43. data/lib/interview/version.rb +1 -1
  44. data/lib/interview/view.rb +1 -1
  45. data/lib/interview.rb +3 -168
  46. metadata +4 -4
  47. data/lib/interview/control_def.rb +0 -36
  48. data/lib/interview/pagination.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ded6f81ccc27790ac8af9e7736ba24dcea1351ef
4
- data.tar.gz: 32e2e873999a080d5d95d12ced1f9609ab624ea7
3
+ metadata.gz: c086485085f2eb7fa260a71e20dc4ada0005abd7
4
+ data.tar.gz: 65f36b1b39de18b9bd330ab4467254b4b1a24c37
5
5
  SHA512:
6
- metadata.gz: 44f793488cf09e87ebceca9105fe524a6dccb9e272861697ebc13e048f89bb5f2b7ab170b4e00a8508d76c4575225480dfa548f14f4726afeff3046652cf6b50
7
- data.tar.gz: 01df35e37381e15ee7f5e2ad8fc0219e4daf29bf9010d1add339737ed9120d5b092afc68a00260cfbe54ee5b354da940940a36c43475b7e9bd4f0d5b5749da83
6
+ metadata.gz: e65be2cb25eea128a5f19da3624aea3816bb03f9f2d8979031e461e7cf83be18be9b5e5a5f7bdcb283e0dcd601e33e2c062095e030ce5d1a2c5d26e2d6ce9c29
7
+ data.tar.gz: 2c610a979c4efe97cb05514b515216cba453d58765e603e7b5e95285607a962558e31c8ddec24c01f5a5116f48a46ee20a5c6d8a248e2fe7444d01462c6b3a6a
@@ -128,5 +128,5 @@ jQuery ->
128
128
  nested_form = $(this)
129
129
  upload_buffer_id = $(this).find('.upload_buffer_id').attr('value')
130
130
  if upload_buffer_id
131
- $.getJSON "upload_buffers/#{upload_buffer_id}.json", (data) ->
131
+ $.getJSON "/upload_buffers/#{upload_buffer_id}.json", (data) ->
132
132
  nested_form.find('.image').attr('src', data.thumb_url)
@@ -11,12 +11,13 @@ module Interview
11
11
  object = find_attribute! :object
12
12
  icon = object.icon
13
13
  end
14
+ controls = add_parent(build_children)
14
15
 
15
- html = Builder::XmlMarkup.new
16
+ html = ::Builder::XmlMarkup.new
16
17
  html.div class: 'clearfix' do
17
- unless @controls.empty?
18
+ unless controls.empty?
18
19
  html.ul class: 'list-inline pull-right' do
19
- @controls.each do |control|
20
+ controls.each do |control|
20
21
  html.li do
21
22
  html << control.render
22
23
  end
@@ -62,7 +62,7 @@ module Interview
62
62
  end
63
63
 
64
64
  def render_card_style
65
- html = Builder::XmlMarkup.new
65
+ html = ::Builder::XmlMarkup.new
66
66
  html.div class: 'row' do
67
67
  html.p class: 'col-xs-3' do
68
68
  html.b caption unless @hide_caption
@@ -82,7 +82,7 @@ module Interview
82
82
  object = find_attribute! :object
83
83
  align = @align || find_attribute(:align)
84
84
 
85
- html = Builder::XmlMarkup.new(indent: 2)
85
+ html = ::Builder::XmlMarkup.new(indent: 2)
86
86
  html.div class: 'form-group' do
87
87
 
88
88
  html.div class: 'col-xs-3' if (@hide_caption or @caption_as_placeholder) and align == 'horizontal'
@@ -112,7 +112,7 @@ module Interview
112
112
  {}
113
113
  end
114
114
  html << form_builder.label(@method, html_opts) do
115
- form_html = Builder::XmlMarkup.new
115
+ form_html = ::Builder::XmlMarkup.new
116
116
  form_html.text! caption
117
117
  form_html.target!.html_safe
118
118
  end
@@ -3,7 +3,7 @@ module Interview
3
3
 
4
4
  def render_read
5
5
  return '' if value.nil?
6
- html = Builder::XmlMarkup.new
6
+ html = ::Builder::XmlMarkup.new
7
7
  if value
8
8
  html.span '', class: 'glyphicon glyphicon-ok'
9
9
  else
@@ -23,7 +23,7 @@ module Interview
23
23
  object = find_attribute! :object
24
24
  align = @align || find_attribute(:align)
25
25
 
26
- html = Builder::XmlMarkup.new
26
+ html = ::Builder::XmlMarkup.new
27
27
  html.div class: "form-group attribute_#{@method.to_s} collapse in" do
28
28
  if align == 'horizontal'
29
29
  html.div class: 'col-xs-9 col-xs-offset-3' do
@@ -37,11 +37,11 @@ module Interview
37
37
  end
38
38
 
39
39
  def render_checkbox
40
- html = Builder::XmlMarkup.new
40
+ html = ::Builder::XmlMarkup.new
41
41
  html << render_write
42
42
  html.text! ' '
43
43
  html << form_builder.label(@method) do
44
- form_html = Builder::XmlMarkup.new
44
+ form_html = ::Builder::XmlMarkup.new
45
45
  form_html.text! caption
46
46
  # if not @hide_tooltip and tooltip != ''
47
47
  # form_html.text! ' '
@@ -7,9 +7,9 @@ module Interview
7
7
  if Object.const_defined?('Gretel')
8
8
  return h.breadcrumbs
9
9
  else
10
- html = Builder::XmlMarkup.new
10
+ html = ::Builder::XmlMarkup.new
11
11
  html.ol class: 'breadcrumb' do
12
- @controls.each do |control|
12
+ add_parent(build_children).each do |control|
13
13
  html << control.render
14
14
  end
15
15
  end
@@ -0,0 +1,49 @@
1
+ module Interview
2
+ class Builder
3
+
4
+ def initialize(options={})
5
+ @target = Interview::Container.new
6
+ end
7
+
8
+ def controls!
9
+ @target.controls
10
+ end
11
+
12
+ def render!
13
+ @target.render
14
+ end
15
+
16
+ def add!(sym, *args, &block)
17
+ if Object.const_defined?(sym.to_s.camelcase) and
18
+ Object.const_get(sym.to_s.camelcase) <= Interview::Control
19
+ control = Object.const_get(sym.to_s.camelcase).new(*args)
20
+ else
21
+ control = Object.const_get("Interview::#{sym.to_s.camelcase}").new(*args)
22
+ end
23
+ @target.add_control control
24
+ if block and control.respond_to? :add_block
25
+ control.add_block(&block)
26
+ elsif block
27
+ temp_target = @target
28
+ @target = control
29
+ yield
30
+ @target = temp_target
31
+ end
32
+ end
33
+
34
+ def <<(control_or_array)
35
+ if control_or_array.kind_of? Array
36
+ @target.add_controls control_or_array
37
+ else
38
+ @target.add_control control_or_array
39
+ end
40
+ end
41
+
42
+ def method_missing(sym, *args, &block)
43
+ add!(sym, *args, &block)
44
+ end
45
+
46
+ protected
47
+
48
+ end
49
+ end
@@ -5,13 +5,13 @@ module Interview
5
5
  attr_accessor :caption
6
6
 
7
7
  def render
8
- html = Builder::XmlMarkup.new
8
+ html = ::Builder::XmlMarkup.new
9
+ controls = add_parent(build_children)
9
10
  if @caption
10
11
  link = Interview::Link.new(caption: @caption)
11
- controls = @controls
12
12
  else
13
- link = @controls.first
14
- controls = @controls[1..-1]
13
+ link = controls.first
14
+ controls = controls[1..-1]
15
15
  end
16
16
  link.url = '#'
17
17
  link.html_class << 'collapse_link'
@@ -7,7 +7,7 @@ module Interview
7
7
  def render
8
8
  object = find_attribute :object
9
9
  if @condition.call(object)
10
- return @controls.map do |control|
10
+ return add_parent(build_children).map do |control|
11
11
  control.render
12
12
  end.join
13
13
  else
@@ -0,0 +1,13 @@
1
+ module Interview
2
+ class Container < Control
3
+
4
+ include HasControls
5
+
6
+ def render
7
+ return add_parent(build_children).map do |control|
8
+ control.render
9
+ end.join
10
+ end
11
+
12
+ end
13
+ end
@@ -15,8 +15,8 @@ module Interview
15
15
  end
16
16
 
17
17
  def render_read
18
- html = Builder::XmlMarkup.new
19
- @controls.each do |control|
18
+ html = ::Builder::XmlMarkup.new
19
+ add_parent(build_children).each do |control|
20
20
  html << control.render
21
21
  end
22
22
  return html.target!
@@ -53,21 +53,5 @@ module Interview
53
53
  return ''
54
54
  end
55
55
 
56
- @definition = ControlDef.new :control
57
-
58
- def self.definition
59
- return @definition
60
- end
61
-
62
- def self.build(opts={})
63
- return @definition.build(opts)
64
- end
65
-
66
- def self.inherited(subclass)
67
- new_def = @definition.deep_dup
68
- new_def.klass = subclass.name.underscore.to_sym
69
- subclass.instance_variable_set :@definition, new_def
70
- end
71
-
72
56
  end
73
57
  end
@@ -11,7 +11,7 @@ module Interview
11
11
 
12
12
  def render
13
13
  container_tag = @container_tag || 'div'
14
- html = Builder::XmlMarkup.new
14
+ html = ::Builder::XmlMarkup.new
15
15
  html_class = @html_class.dup
16
16
  html_class << 'dropdown'
17
17
  html.tag! container_tag, class: html_class.join(' ') do
@@ -25,7 +25,7 @@ module Interview
25
25
  html.span '', class: 'caret'
26
26
  end
27
27
  html.ul class: 'dropdown-menu' do
28
- @controls.each do |control|
28
+ add_parent(build_children).each do |control|
29
29
  html.li do
30
30
  html << control.render
31
31
  end
@@ -14,11 +14,11 @@ module Interview
14
14
  end
15
15
  return h.form_for(object, role: 'form', html: html_options) do |form_builder|
16
16
  @form_builder = form_builder
17
- html = Builder::XmlMarkup.new(indent: 2)
17
+ html = ::Builder::XmlMarkup.new(indent: 2)
18
18
 
19
19
  render_default_controls(html)
20
20
 
21
- @controls.each do |control|
21
+ add_parent(build_children).each do |control|
22
22
  html << control.render
23
23
  html.text! ' ' if @align == 'inline'
24
24
  end
@@ -4,7 +4,7 @@ module Interview
4
4
  def render
5
5
  object = find_attribute!(:object)
6
6
 
7
- html = Builder::XmlMarkup.new
7
+ html = ::Builder::XmlMarkup.new
8
8
  if object.errors.any?
9
9
  html.div class: 'alert alert-danger' do
10
10
  html.h4 h.translate("errors.template.header", count: object.errors.count, model: object.class.model_name.human)
@@ -7,14 +7,15 @@ module Interview
7
7
 
8
8
  def render
9
9
  objects = @objects || find_attribute!(:objects)
10
+ controls = add_parent(build_children)
10
11
  @object = find_attribute!(:object)
11
12
  sortable_id = "sortable_#{@object.class.model_name.plural}" if @sortable
12
- html = Builder::XmlMarkup.new
13
+ html = ::Builder::XmlMarkup.new
13
14
  html.table class: 'table' do
14
15
  html.thead do
15
16
  html.tr do
16
17
  html.th '' if @sortable
17
- @controls.each do |control|
18
+ controls.each do |control|
18
19
  html.th do
19
20
  html << control.caption
20
21
  end
@@ -34,7 +35,7 @@ module Interview
34
35
  html.span '', class: 'handle glyphicon glyphicon-resize-vertical'
35
36
  end
36
37
  end
37
- @controls.each do |control|
38
+ controls.each do |control|
38
39
  html.td do
39
40
  html << control.render
40
41
  end
@@ -4,7 +4,7 @@ module HasControls
4
4
 
5
5
  def initialize(params={})
6
6
  super
7
- @controls = self.class.definition.build_controls_for self
7
+ @controls = []
8
8
  end
9
9
 
10
10
  def add_control(control, &block)
@@ -14,7 +14,7 @@ module HasControls
14
14
  end
15
15
 
16
16
  def add_controls(controls)
17
- controls.each { |control| control.parent = self }
17
+ add_parent(controls)
18
18
  @controls += controls
19
19
  end
20
20
 
@@ -28,16 +28,13 @@ module HasControls
28
28
  end.flatten
29
29
  end
30
30
 
31
- def self.included(mod)
32
- mod.extend ClassMethods
31
+ def build_children
32
+ return @controls
33
33
  end
34
34
 
35
- module ClassMethods
36
-
37
- def control(klass, params={}, &block)
38
- @definition.control(klass, params, &block)
39
- end
40
-
35
+ def add_parent(controls)
36
+ controls.each { |control| control.parent = self }
37
+ return controls
41
38
  end
42
39
 
43
40
  end
@@ -3,7 +3,13 @@ module Interview
3
3
 
4
4
  def initialize(params={}, &block)
5
5
  super
6
- @html = Builder::XmlMarkup.new
6
+ @html = ::Builder::XmlMarkup.new
7
+ if block
8
+ yield @html
9
+ end
10
+ end
11
+
12
+ def add_block(&block)
7
13
  yield @html
8
14
  end
9
15
 
@@ -11,7 +11,7 @@ module Interview
11
11
 
12
12
  return '' if value.nil? and @hide_if_not_exists
13
13
 
14
- html = Builder::XmlMarkup.new
14
+ html = ::Builder::XmlMarkup.new
15
15
  opts = {class: "image_#{image_style}"}
16
16
  opts[:class] += ' ' + @html_class.join(' ') unless @html_class.empty? or @surrounding_tag
17
17
  html.div opts do
@@ -27,7 +27,7 @@ module Interview
27
27
  def render_write
28
28
  image_style = @image_style || :thumb
29
29
 
30
- html = Builder::XmlMarkup.new
30
+ html = ::Builder::XmlMarkup.new
31
31
  html.div class: 'image_attribute_container' do
32
32
  unless value.nil? and @hide_if_not_exists
33
33
  html.div class: 'inline-block' do
@@ -8,7 +8,7 @@ module Interview
8
8
  image_style = @image_style || :thumb
9
9
  images = value
10
10
 
11
- html = Builder::XmlMarkup.new
11
+ html = ::Builder::XmlMarkup.new
12
12
  render_gallery(html, images, submethod, image_style, @light_box_image_style)
13
13
  return html.target!
14
14
  end
@@ -20,7 +20,7 @@ module Interview
20
20
  images = object.send @method
21
21
  model = images.klass.model_name.singular
22
22
 
23
- html = Builder::XmlMarkup.new
23
+ html = ::Builder::XmlMarkup.new
24
24
  html.div class: 'image-upload-group' do
25
25
 
26
26
  html << form_builder.hidden_field("#{@method.singularize}_ids", class: 'image-ids')
@@ -2,7 +2,7 @@ module Interview
2
2
  class ImageLightBox < Control
3
3
 
4
4
  def render
5
- html = Builder::XmlMarkup.new
5
+ html = ::Builder::XmlMarkup.new
6
6
  html.div id: "blueimp-gallery", class: "blueimp-gallery" do
7
7
  html.div '', class: "slides"
8
8
  html.h3 '', class: "title"
@@ -102,7 +102,7 @@ module Interview
102
102
  end
103
103
 
104
104
  def render_list_style(url, html_class=[], html_options={})
105
- html = Builder::XmlMarkup.new
105
+ html = ::Builder::XmlMarkup.new
106
106
  li_class = @active ? 'active' : ''
107
107
  html.li class: li_class do
108
108
  html << render_link(url, html_class, html_options)
@@ -111,17 +111,18 @@ module Interview
111
111
  end
112
112
 
113
113
  def render_link(url, html_class=[], html_options={})
114
+ controls = add_parent(build_children)
114
115
  class_string = html_class.join(' ')
115
116
  html_options[:class] = class_string unless html_class.empty?
116
117
  html_options[:data] = @html_data unless @html_data.empty?
117
118
  return h.link_to(url, html_options) do
118
- html = Builder::XmlMarkup.new
119
- if @controls.empty?
119
+ html = ::Builder::XmlMarkup.new
120
+ if controls.empty?
120
121
  html.span '', class: "glyphicon glyphicon-#{@image}" if @image
121
122
  html.text! ' ' if @image and @caption
122
123
  html << @caption if @caption
123
124
  else
124
- @controls.each do |control|
125
+ controls.each do |control|
125
126
  html << control.render
126
127
  end
127
128
  end
@@ -7,10 +7,10 @@ module Interview
7
7
 
8
8
  def render
9
9
  objects = @objects || find_attribute!(:objects)
10
- html = Builder::XmlMarkup.new
10
+ html = ::Builder::XmlMarkup.new
11
11
  objects.each do |object|
12
12
  @object = object
13
- @controls.each do |control| # todo: controls neu initialisieren?
13
+ add_parent(build_children).each do |control| # todo: controls neu initialisieren?
14
14
  html << control.render
15
15
  end
16
16
  end
@@ -7,14 +7,15 @@ module Interview
7
7
  def render
8
8
  image_size = @image_size || :thumb
9
9
  object = find_attribute :object
10
+ controls = add_parent(build_children)
10
11
  @object = object
11
- html = Builder::XmlMarkup.new(indent: 2)
12
+ html = ::Builder::XmlMarkup.new(indent: 2)
12
13
  html.div class: 'media' do
13
- @controls[0].html_class << 'pull-left' if @controls[0].respond_to? 'html_class'
14
- html << @controls.first.render
14
+ controls[0].html_class << 'pull-left' if controls[0].respond_to? 'html_class'
15
+ html << controls.first.render
15
16
  html.div class: 'media-body' do
16
- @controls[1].html_class << 'media-heading' if @controls[1].respond_to? 'html_class'
17
- @controls[1..-1].each do |control|
17
+ controls[1].html_class << 'media-heading' if controls[1].respond_to? 'html_class'
18
+ controls[1..-1].each do |control|
18
19
  html << control.render
19
20
  end
20
21
  end
@@ -7,9 +7,9 @@ module Interview
7
7
  def render
8
8
  auto_set_active
9
9
 
10
- html = Builder::XmlMarkup.new
10
+ html = ::Builder::XmlMarkup.new
11
11
  html.ul class: 'nav nav-pills nav-stacked' do
12
- @controls.each do |control|
12
+ add_parent(build_children).each do |control|
13
13
  html << control.render
14
14
  end
15
15
  end
@@ -25,12 +25,12 @@ module Interview
25
25
  html << @caption if @caption
26
26
  end)
27
27
 
28
- html = Builder::XmlMarkup.new
28
+ html = ::Builder::XmlMarkup.new
29
29
  html.li class: css_class do
30
30
  html << link.render
31
31
  end
32
32
  if show_siblings
33
- @controls.each do |c|
33
+ add_parent(build_children).each do |c|
34
34
  html << c.render
35
35
  end
36
36
  end
@@ -10,12 +10,12 @@ module Interview
10
10
  css_class += " active" if @active
11
11
  show_siblings = @active || siblings.any? { |sib| sib.active }
12
12
 
13
- html = Builder::XmlMarkup.new
13
+ html = ::Builder::XmlMarkup.new
14
14
  html.li class: css_class do
15
15
  html << super
16
16
  end
17
17
  if show_siblings
18
- @controls.each do |c|
18
+ add_parent(build_children).each do |c|
19
19
  html << c.render
20
20
  end
21
21
  end
@@ -9,7 +9,7 @@ module Interview
9
9
  assoc_form_builder = find_attribute! :form_builder
10
10
  assoc_method = find_attribute! :assoc_method
11
11
 
12
- html = Builder::XmlMarkup.new
12
+ html = ::Builder::XmlMarkup.new
13
13
  html.div class: 'nested_form_container' do
14
14
  if @image_based
15
15
  html << Interview::NestedFormAddImages.new.render
@@ -38,9 +38,9 @@ module Interview
38
38
  def render_nested_form(form_builder)
39
39
  @form_builder = form_builder
40
40
  @object = form_builder.object
41
- html = Builder::XmlMarkup.new
41
+ html = ::Builder::XmlMarkup.new
42
42
  html.div class: 'nested_form collapse in' do
43
- @controls.each do |control|
43
+ add_parent(build_children).each do |control|
44
44
  html << control.render
45
45
  end
46
46
  html << form_builder.hidden_field(:id)
@@ -5,7 +5,7 @@ module Interview
5
5
 
6
6
  def render
7
7
  if @style and @style.to_sym == :horizontal_form
8
- html = Builder::XmlMarkup.new # todo: in eigenes Objekt auslagern?
8
+ html = ::Builder::XmlMarkup.new # todo: in eigenes Objekt auslagern?
9
9
  html.div class: 'row' do
10
10
  html.div class: 'col-xs-9 col-xs-offset-3' do
11
11
  html << render_link
@@ -18,7 +18,7 @@ module Interview
18
18
  end
19
19
 
20
20
  def render_link
21
- html = Builder::XmlMarkup.new
21
+ html = ::Builder::XmlMarkup.new
22
22
  html.div class: "clearfix" do
23
23
  html.span class: "btn btn-default fileinput-button" do
24
24
  html.span "Bilder hinzufügen" # todo
@@ -5,7 +5,7 @@ module Interview
5
5
 
6
6
  def render
7
7
  if @style and @style.to_sym == :horizontal_form
8
- html = Builder::XmlMarkup.new # todo: in eigenes Objekt auslagern?
8
+ html = ::Builder::XmlMarkup.new # todo: in eigenes Objekt auslagern?
9
9
  html.div class: 'row' do
10
10
  html.div class: 'col-xs-9 col-xs-offset-3' do
11
11
  html << render_link
@@ -48,7 +48,7 @@ module Interview
48
48
  data_content[poly_class.model_name.singular] = html
49
49
  end
50
50
 
51
- html = Builder::XmlMarkup.new
51
+ html = ::Builder::XmlMarkup.new
52
52
  html.div do
53
53
  html << h.select_tag("add_link_class", h.options_for_select(select_options), class: 'form-control', style: 'display: inline; width: auto;')
54
54
  html.text! ' '
@@ -5,7 +5,7 @@ module Interview
5
5
 
6
6
  def render
7
7
  if @style and @style.to_sym == :horizontal_form
8
- html = Builder::XmlMarkup.new
8
+ html = ::Builder::XmlMarkup.new
9
9
  html.div class: 'row' do
10
10
  html.div class: 'col-xs-9 col-xs-offset-3' do
11
11
  html << render_link
@@ -1,8 +1,12 @@
1
1
  module Interview
2
- module ObjectContext # todo: Überdenken
2
+ module ObjectContext
3
3
 
4
4
  attr_reader :object
5
5
 
6
+ def initialize
7
+ puts "DEPRECATION WARNING: Interview::ObjectContext is deprecated."
8
+ end
9
+
6
10
  def object=(object)
7
11
  if object.is_a? String
8
12
  @object = Object::const_get(object.camelcase).new
@@ -34,7 +34,7 @@ module Interview
34
34
 
35
35
  def render_radios
36
36
  object = find_attribute!(:object)
37
- html = Builder::XmlMarkup.new
37
+ html = ::Builder::XmlMarkup.new
38
38
  get_options(object).each do |option|
39
39
  html.div class: 'radio' do
40
40
  html.label do
@@ -3,10 +3,10 @@ module Interview
3
3
  include HasControls
4
4
 
5
5
  def render
6
- html = Builder::XmlMarkup.new
6
+ html = ::Builder::XmlMarkup.new
7
7
  html.div class: 'panel panel-default' do
8
8
  html.div class: 'panel-body' do
9
- @controls.each do |control|
9
+ add_parent(build_children).each do |control|
10
10
  html << control.render
11
11
  end
12
12
  end
@@ -35,7 +35,7 @@ module Interview
35
35
  [ poly_class.human_name, poly_class.name ]
36
36
  end
37
37
 
38
- html = Builder::XmlMarkup.new
38
+ html = ::Builder::XmlMarkup.new
39
39
  html.div do
40
40
  html << h.select_tag("add_link_class", h.options_for_select(select_options), class: 'form-control', style: 'display: inline; width: auto;')
41
41
  html.text! ' '
@@ -11,7 +11,7 @@ module Interview
11
11
 
12
12
  def render
13
13
  html_class = @html_class
14
- html = Builder::XmlMarkup.new
14
+ html = ::Builder::XmlMarkup.new
15
15
  opts = { class: "progress" }
16
16
  opts[:class] += " collapse" if @hidden
17
17
  opts[:class] += ' ' + @html_class.join(' ') unless @html_class.empty?
@@ -4,7 +4,7 @@ module Interview
4
4
  def render
5
5
  object = find_attribute! :object
6
6
  return h.form_tag(h.polymorphic_path(object.class.model_name.plural, action: 'search'), method: :get, class: 'form-inline', role: 'form') do
7
- html = Builder::XmlMarkup.new(indent: 2)
7
+ html = ::Builder::XmlMarkup.new(indent: 2)
8
8
  html.div do
9
9
  html.div class: 'form-group' do
10
10
  html << h.text_field_tag(:search, h.params[:search], class: 'form-control')
@@ -3,7 +3,7 @@ module Interview
3
3
  attr_accessor :style
4
4
 
5
5
  def render
6
- html = Builder::XmlMarkup.new
6
+ html = ::Builder::XmlMarkup.new
7
7
  if @style and @style.to_sym == :line
8
8
  html.hr
9
9
  elsif @style and @style.to_sym == :break
data/lib/interview/tab.rb CHANGED
@@ -6,11 +6,11 @@ module Interview
6
6
  attr_accessor :caption, :active
7
7
 
8
8
  def render
9
- html = Builder::XmlMarkup.new
9
+ html = ::Builder::XmlMarkup.new
10
10
  html_class = 'tab-pane'
11
11
  html_class += ' active' if @active
12
12
  html.div class: html_class, id: @caption do
13
- @controls.each do |control|
13
+ add_parent(build_children).each do |control|
14
14
  html << control.render
15
15
  end
16
16
  end
@@ -4,13 +4,14 @@ module Interview
4
4
  include HasControls
5
5
 
6
6
  def render
7
- if @controls.none? { |c| c.active }
8
- @controls.first.active = true
7
+ controls = add_parent(build_children)
8
+ if controls.none? { |c| c.active }
9
+ controls.first.active = true
9
10
  end
10
11
 
11
- html = Builder::XmlMarkup.new
12
+ html = ::Builder::XmlMarkup.new
12
13
  html.ul class: 'nav nav-tabs tab_box' do
13
- @controls.each do |control|
14
+ controls.each do |control|
14
15
  html_class = control.active ? 'active' : ''
15
16
  html.li class: html_class do
16
17
  html.a control.caption, href: "##{control.caption}", :'data-toogle' => 'tab'
@@ -18,7 +19,7 @@ module Interview
18
19
  end
19
20
  end
20
21
  html.div class: 'tab-content' do
21
- @controls.each do |control|
22
+ controls.each do |control|
22
23
  html << control.render
23
24
  end
24
25
  end
@@ -10,7 +10,7 @@ module Interview
10
10
  end
11
11
 
12
12
  def render
13
- html = Builder::XmlMarkup.new
13
+ html = ::Builder::XmlMarkup.new
14
14
  if @style
15
15
  opts = {}
16
16
  opts[:class] = @html_class.join(' ') unless @html_class.empty?
@@ -29,13 +29,13 @@ module Interview
29
29
  if @bold
30
30
  html.b do
31
31
  html << @text # todo: besser .text! statt << ?
32
- @controls.each do |control|
32
+ add_parent(build_children).each do |control|
33
33
  html << control.render
34
34
  end
35
35
  end
36
36
  else
37
37
  html << @text if @text # todo: besser .text! statt << ?
38
- @controls.each do |control|
38
+ add_parent(build_children).each do |control|
39
39
  html << control.render
40
40
  end
41
41
  end
@@ -26,7 +26,7 @@ module Interview
26
26
  end
27
27
 
28
28
  def render_popover_style
29
- html = Builder::XmlMarkup.new
29
+ html = ::Builder::XmlMarkup.new
30
30
  html.text! ' '
31
31
  html.a href: '#', class: 'tip', :'data-toggle' => 'popover', :'data-content' => tooltip do
32
32
  html.span '', class: 'glyphicon glyphicon-question-sign'
@@ -1,3 +1,3 @@
1
1
  module Interview
2
- VERSION = "0.0.11"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -98,7 +98,7 @@ module Interview
98
98
  end
99
99
  end
100
100
 
101
- html = @controls.map { |c| c.render }.join
101
+ html = add_parent(build_children).map { |c| c.render }.join
102
102
 
103
103
  @object = tmp_object
104
104
  @objects = tmp_objects
data/lib/interview.rb CHANGED
@@ -4,9 +4,10 @@ require "builder"
4
4
 
5
5
  require "interview/version"
6
6
 
7
- require "interview/control_def"
8
7
  require "interview/control"
9
8
  require "interview/has_controls"
9
+ require "interview/container"
10
+ require "interview/builder"
10
11
  require "interview/object_context"
11
12
 
12
13
  require "interview/text"
@@ -28,7 +29,6 @@ require "interview/media_object"
28
29
  require "interview/panel"
29
30
  require "interview/collapse_container"
30
31
  require "interview/condition_container"
31
- require "interview/pagination"
32
32
 
33
33
  require "interview/attribute"
34
34
  require "interview/string_attribute"
@@ -90,175 +90,10 @@ module ActiveRecord
90
90
  return objects.map { |object| object.human_id }
91
91
  end
92
92
 
93
- # todo: auslagern in eigenes gem
94
- def self.filter(filter)
95
- relation = self
96
- # self.joins_for_filter(filter).each do |join_table|
97
- # relation = relation.joins(join_table)
98
- # end
99
- return relation.where(*self.filter_to_sql(filter))
100
- end
101
-
102
- def self.joins_for_filter(filter)
103
- join_tables = []
104
- filter.each do |attr, filter|
105
- if assoc = self.reflect_on_association(attr) and assoc.macro != :belongs_to
106
- join_tables << assoc.plural_name.to_sym # todo
107
- end
108
- end
109
- return join_tables.uniq
110
- end
111
-
112
- def self.filter_to_sql(filter)
113
- if filter.is_a? Hash # todo
114
- result = hash_filter_to_sql(filter)
115
- elsif filter.respond_to? :each
116
- result = filter_combination_to_sql(filter)
117
- end # todo: else
118
- return result
119
- end
120
-
121
- def self.filter_combination_to_sql(filter)
122
- if [:and, :or].include? filter.first
123
- combination = filter.first
124
- filter = filter[1..-1]
125
- end
126
- combination ||= :or
127
- sqls = []
128
- values = []
129
- filter.each do |f|
130
- f = self.filter_to_sql(f)
131
- sqls << f.first
132
- values += f[1..-1]
133
- end
134
- sql = '(' + sqls.join(" #{combination.to_s.upcase} ") + ')'
135
- return [sql] + values
136
- end
137
-
138
- def self.hash_filter_to_sql(filter)
139
- sqls = []
140
- values = []
141
- filter.each do |attr, filter|
142
- if self.reflect_on_association(attr)
143
- result = self.assoc_filter_to_sql(attr, filter)
144
- elsif column = self.columns_hash[attr.to_s]
145
- result = case column.type
146
- when :string
147
- self.string_filter_to_sql(attr, filter)
148
- when :integer, :decimal
149
- self.number_filter_to_sql(attr, filter)
150
- when :date
151
- self.date_filter_to_sql(attr, filter)
152
- when :boolean
153
- self.boolean_filter_to_sql(attr, filter)
154
- end
155
- # todo: erweitern
156
- else
157
- raise "Not possible to set a filter for #{attr}"
158
- end
159
- sqls << result.first
160
- values += result[1..-1]
161
- end
162
- sql = sqls.join(' AND ')
163
- return [sql] + values
164
- end
165
-
166
- def self.string_filter_to_sql(attr, filter, negation=false)
167
- negation = negation ? 'NOT ' : ''
168
- if filter.respond_to?(:each)
169
- return self.value_combination_to_sql(attr, filter, :string)
170
- else
171
- sql = "#{negation}#{attr} = ?"
172
- end
173
- return [sql, filter]
174
- end
175
-
176
- def self.number_filter_to_sql(attr, filter, negation=false)
177
- negation = negation ? 'NOT ' : ''
178
- if filter.respond_to?(:each)
179
- return self.value_combination_to_sql(attr, filter, :number)
180
- elsif filter.is_a? String
181
- unless result = filter.match(/^([!<>=]*)(\d+\.?\d*)$/)
182
- raise "invalid number filter: '#{filter}'"
183
- end
184
- connective = result[1].blank? ? '=' : result[1]
185
- value = result[2].include?('.') ? result[2].to_f : result[2].to_i
186
- sql = "#{negation}#{attr} #{connective} ?"
187
- values = [value]
188
- else
189
- sql = "#{negation}#{attr} = ?"
190
- values = [filter]
191
- end
192
- return [sql] + values
193
- end
194
-
195
- def self.date_filter_to_sql(attr, filter, negation=false)
196
- negation = negation ? 'NOT ' : ''
197
- if filter.respond_to?(:each)
198
- if filter.size != 2 # todo: value_combination einbauen
199
- raise "invalid date filter: #{filter.inspect} 2 elements expected, #{filter.size} given"
200
- end
201
- sql = "#{negation}#{attr} BETWEEN ? AND ?"
202
- values = filter
203
- else
204
- sql = "#{negation}#{attr} = ?"
205
- values = [filter]
206
- end
207
- return [sql] + values
208
- end
209
-
210
- def self.boolean_filter_to_sql(attr, filter, negation=false)
211
- if filter.respond_to?(:each)
212
- return self.value_combination_to_sql(attr, filter, :boolean)
213
- end
214
- negation = negation ? 'NOT ' : ''
215
- return ["#{negation}#{attr} = ?", filter]
216
- end
217
-
218
- def self.assoc_filter_to_sql(attr, filter, negation=false)
219
- if filter.respond_to?(:each)
220
- return self.value_combination_to_sql(attr, filter, :assoc)
221
- end
222
- negation = negation ? 'NOT ' : ''
223
- assoc = self.reflect_on_association(attr)
224
- if assoc.macro == :has_and_belongs_to_many
225
- number_filter = self.number_filter_to_sql(assoc.association_foreign_key, filter)
226
- values = number_filter[1..-1]
227
- sql = "id #{negation}IN (SELECT #{assoc.foreign_key} FROM #{assoc.join_table} WHERE #{number_filter.first})"
228
- end # todo: erweitern
229
- return [sql] + values
230
- end
231
-
232
- def self.value_combination_to_sql(attr, filter, filter_type)
233
- # todo: check if set is possible
234
- if filter.first == :not
235
- return self.send("#{filter_type}_filter_to_sql", attr, filter[1], true)
236
- elsif [:and, :or].include? filter.first
237
- combination = filter.first
238
- filter = filter[1..-1]
239
- end
240
- combination ||= :or
241
- sqls = []
242
- values = []
243
- filter.each do |f|
244
- f = self.send("#{filter_type}_filter_to_sql", attr, f)
245
- sqls << f.first
246
- values += f[1..-1]
247
- end
248
- sql = '(' + sqls.join(" #{combination.to_s.upcase} ") + ')'
249
- return [sql] + values
250
- end
251
-
252
93
  def self.human_name(options={})
253
94
  options = {scope: [self.i18n_scope, :models], count: 1}.merge(options)
254
95
  I18n.translate(self.name.underscore, options)
255
96
  end
256
-
257
- end
258
- end
259
-
260
- module ActiveRecord::Associations::Builder
261
- class CollectionAssociation < Association
262
- include AssociationMethods
97
+
263
98
  end
264
99
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jannes Köhler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-22 00:00:00.000000000 Z
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,12 +126,13 @@ files:
126
126
  - lib/interview/attribute.rb
127
127
  - lib/interview/boolean_attribute.rb
128
128
  - lib/interview/breadcrumbs.rb
129
+ - lib/interview/builder.rb
129
130
  - lib/interview/button.rb
130
131
  - lib/interview/collapse_container.rb
131
132
  - lib/interview/condition_container.rb
133
+ - lib/interview/container.rb
132
134
  - lib/interview/container_attribute.rb
133
135
  - lib/interview/control.rb
134
- - lib/interview/control_def.rb
135
136
  - lib/interview/date_attribute.rb
136
137
  - lib/interview/datetime_attribute.rb
137
138
  - lib/interview/decimal_attribute.rb
@@ -159,7 +160,6 @@ files:
159
160
  - lib/interview/nested_form_remove_link.rb
160
161
  - lib/interview/object_context.rb
161
162
  - lib/interview/option_attribute.rb
162
- - lib/interview/pagination.rb
163
163
  - lib/interview/panel.rb
164
164
  - lib/interview/polymorphic_add_link.rb
165
165
  - lib/interview/progress_bar.rb
@@ -1,36 +0,0 @@
1
- class ControlDef
2
-
3
- attr_accessor :klass
4
- attr_reader :params, :controls
5
-
6
- def initialize(klass, params={})
7
- @klass = klass.to_sym
8
- @params = params
9
- @controls = []
10
- end
11
-
12
- def control(klass, params={}, &block)
13
- control = ControlDef.new(klass, params)
14
- @controls << control
15
- yield(control) if block_given?
16
- end
17
-
18
- def build(params={})
19
- control = Object::const_get("#{@klass.to_s.camelcase}").new(@params.merge(params))
20
- if control.respond_to? :add_controls
21
- control.add_controls build_controls_for(control)
22
- end
23
- return control
24
- end
25
-
26
- def build_controls_for(parent_control)
27
- return @controls.map { |c| c.build(parent: parent_control) }
28
- end
29
-
30
- def deep_dup
31
- new_definition = self.class.new(@klass, @params.deep_dup)
32
- new_definition.instance_variable_set :@controls, @controls.deep_dup
33
- return new_definition
34
- end
35
-
36
- end
@@ -1,12 +0,0 @@
1
- module Interview
2
- class Pagination < Control
3
-
4
- attr_accessor :objects
5
-
6
- def render
7
- objects = @objects || find_attribute!(:objects)
8
- return h.paginate(objects)
9
- end
10
-
11
- end
12
- end