gather_content-api 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +7 -0
  3. data/README.md +161 -35
  4. data/gather_content-api.gemspec +1 -1
  5. data/lib/gather_content.rb +2 -0
  6. data/lib/gather_content/api.rb +16 -15
  7. data/lib/gather_content/config.rb +9 -0
  8. data/lib/gather_content/config/builder.rb +20 -0
  9. data/lib/gather_content/config/elements.rb +15 -0
  10. data/lib/gather_content/config/elements/base.rb +32 -0
  11. data/lib/gather_content/config/elements/choice_checkbox.rb +32 -0
  12. data/lib/gather_content/config/elements/choice_radio.rb +62 -0
  13. data/lib/gather_content/config/elements/files.rb +17 -0
  14. data/lib/gather_content/config/elements/option.rb +30 -0
  15. data/lib/gather_content/config/elements/other_option.rb +26 -0
  16. data/lib/gather_content/config/elements/section.rb +31 -0
  17. data/lib/gather_content/config/elements/text.rb +32 -0
  18. data/lib/gather_content/config/tab.rb +30 -0
  19. data/lib/gather_content/config/tabs.rb +13 -0
  20. data/lib/gather_content/dsl.rb +15 -0
  21. data/lib/gather_content/dsl/base.rb +28 -0
  22. data/lib/gather_content/dsl/choice_checkbox.rb +19 -0
  23. data/lib/gather_content/dsl/choice_radio.rb +25 -0
  24. data/lib/gather_content/dsl/config.rb +16 -0
  25. data/lib/gather_content/dsl/files.rb +12 -0
  26. data/lib/gather_content/dsl/option.rb +29 -0
  27. data/lib/gather_content/dsl/other_option.rb +18 -0
  28. data/lib/gather_content/dsl/section.rb +24 -0
  29. data/lib/gather_content/dsl/tab.rb +54 -0
  30. data/lib/gather_content/dsl/text.rb +29 -0
  31. data/lib/gather_content/error.rb +1 -1
  32. data/lib/gather_content/version.rb +1 -1
  33. data/spec/gather_content/config/builder_spec.rb +42 -0
  34. data/spec/gather_content/config/elements/choice_checkbox_spec.rb +78 -0
  35. data/spec/gather_content/config/elements/choice_radio_spec.rb +175 -0
  36. data/spec/gather_content/config/elements/files_spec.rb +23 -0
  37. data/spec/gather_content/config/elements/option_spec.rb +88 -0
  38. data/spec/gather_content/config/elements/other_option_spec.rb +124 -0
  39. data/spec/gather_content/config/elements/section_spec.rb +80 -0
  40. data/spec/gather_content/config/elements/text_spec.rb +163 -0
  41. data/spec/gather_content/config/tab_spec.rb +120 -0
  42. data/spec/gather_content/dsl/choice_checkbox_spec.rb +25 -0
  43. data/spec/gather_content/dsl/choice_radio_spec.rb +47 -0
  44. data/spec/gather_content/dsl/files_spec.rb +12 -0
  45. data/spec/gather_content/dsl/section_spec.rb +37 -0
  46. data/spec/gather_content/dsl/tab_spec.rb +107 -0
  47. data/spec/gather_content/dsl/text_spec.rb +48 -0
  48. data/spec/spec_helper.rb +1 -1
  49. data/spec/support/shared_examples/dsl.rb +63 -0
  50. data/spec/support/shared_examples/element.rb +77 -0
  51. metadata +63 -4
@@ -0,0 +1,17 @@
1
+ require 'gather_content/config/elements/base'
2
+
3
+ module GatherContent
4
+ module Config
5
+ module Element
6
+ class Files < Base
7
+ attr_accessor :options
8
+
9
+ def serialize(options = nil)
10
+ super.merge({
11
+ type: 'files'
12
+ })
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module GatherContent
2
+ module Config
3
+ module Element
4
+ class Option
5
+ attr_accessor :name, :label, :selected
6
+
7
+ def initialize(name = nil, label = nil, selected = nil)
8
+ @name = name
9
+ @label = label
10
+ @selected = selected
11
+ end
12
+
13
+ def serialize(options = nil)
14
+ raise ArgumentError, "name is required" unless name.present?
15
+ raise ArgumentError, "label is required" unless label.present?
16
+
17
+ {
18
+ name: name,
19
+ label: label,
20
+ selected: !!selected
21
+ }
22
+ end
23
+
24
+ def to_json(options = nil)
25
+ serialize.to_json(options)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ require 'gather_content/config/elements/option'
2
+
3
+ module GatherContent
4
+ module Config
5
+ module Element
6
+ class OtherOption < Option
7
+ attr_accessor :name, :label, :selected, :value
8
+
9
+ def initialize(name = nil, label = nil, selected = nil, value = nil)
10
+ super(name, label, selected)
11
+ @value = value
12
+ end
13
+
14
+ def serialize(options = nil)
15
+ base = super(options)
16
+
17
+ value = !!selected ? self.value : ""
18
+
19
+ base.merge({
20
+ value: value
21
+ })
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ module GatherContent
2
+ module Config
3
+ module Element
4
+ class Section
5
+ attr_accessor :name, :title, :subtitle
6
+
7
+ def initialize(name = "", title = "", subtitle = "")
8
+ @name = name
9
+ @title = title
10
+ @subtitle = subtitle
11
+ end
12
+
13
+ def serialize(options = nil)
14
+ raise ArgumentError, "name is required" unless name.present?
15
+ raise ArgumentError, "title is required" unless title.present?
16
+
17
+ {
18
+ type: "section",
19
+ name: name,
20
+ title: title,
21
+ subtitle: subtitle
22
+ }
23
+ end
24
+
25
+ def to_json(options = nil)
26
+ serialize.to_json(options)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ require 'gather_content/config/elements/base'
2
+
3
+ module GatherContent
4
+ module Config
5
+ module Element
6
+ class Text < Base
7
+ attr_accessor :value, :limit_type, :limit, :plain_text
8
+
9
+ def initialize(name = "", required = false, label = "", microcopy = "", value = "", limit_type = :chars, limit = 0, plain_text = true)
10
+ super(name, required, label, microcopy)
11
+ @value = value
12
+ @limit_type = limit_type
13
+ @limit = limit
14
+ @plain_text = plain_text
15
+ end
16
+
17
+ def serialize(options = nil)
18
+ raise ArgumentError, "limit_type is can only be :words or :chars" unless [ :words, :chars ].include?(limit_type)
19
+ raise ArgumentError, "limit be a positive number" if limit.to_i < 0
20
+
21
+ super.merge({
22
+ type: 'text',
23
+ value: value,
24
+ limit_type: limit_type.to_s,
25
+ limit: limit.to_i,
26
+ plain_text: !!plain_text
27
+ })
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ module GatherContent
2
+ module Config
3
+ class Tab
4
+ attr_accessor :label, :name, :hidden, :elements
5
+
6
+ def initialize(label = "", name = "", hidden = false, elements = [])
7
+ self.label = label
8
+ self.name = name
9
+ self.hidden = hidden
10
+ self.elements = elements
11
+ end
12
+
13
+ def serialize(options = nil)
14
+ raise ArgumentError, "name is required" unless name.present?
15
+ raise ArgumentError, "label is required" unless label.present?
16
+
17
+ {
18
+ label: label,
19
+ name: name,
20
+ hidden: !!hidden,
21
+ elements: elements.map{ |el| el.serialize(options) }
22
+ }
23
+ end
24
+
25
+ def to_json(options = nil)
26
+ serialize.to_json(options)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ module GatherContent
2
+ module Config
3
+ class Tabs < Array
4
+ def serialize(options = nil)
5
+ self.map{ |el| el.serialize(options) }
6
+ end
7
+
8
+ def to_json(options = nil)
9
+ self.serialize.to_json
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ require 'gather_content/dsl/base'
2
+ require 'gather_content/dsl/choice_checkbox'
3
+ require 'gather_content/dsl/choice_radio'
4
+ require 'gather_content/dsl/config'
5
+ require 'gather_content/dsl/files'
6
+ require 'gather_content/dsl/option'
7
+ require 'gather_content/dsl/other_option'
8
+ require 'gather_content/dsl/section'
9
+ require 'gather_content/dsl/tab'
10
+ require 'gather_content/dsl/text'
11
+
12
+ module GatherContent
13
+ module DSL
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ require 'gather_content/config/elements/files'
2
+
3
+ module GatherContent
4
+ module DSL
5
+ class Base
6
+ def initialize(tab, child)
7
+ @child = child
8
+ tab.elements << @child
9
+ end
10
+
11
+ def name(name)
12
+ @child.name = name
13
+ end
14
+
15
+ def label(label)
16
+ @child.label = label
17
+ end
18
+
19
+ def required(required)
20
+ @child.required = required
21
+ end
22
+
23
+ def microcopy(microcopy)
24
+ @child.microcopy = microcopy
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ require 'gather_content/dsl/base'
2
+ require 'gather_content/config/elements/choice_checkbox'
3
+ require 'gather_content/dsl/option'
4
+
5
+ module GatherContent
6
+ module DSL
7
+ class ChoiceCheckbox < Base
8
+ def initialize(tab)
9
+ @choice_checkbox = GatherContent::Config::Element::ChoiceCheckbox.new
10
+ super(tab, @choice_checkbox)
11
+ end
12
+
13
+ def option(&block)
14
+ dsl = GatherContent::DSL::Option.new(@choice_checkbox)
15
+ dsl.instance_eval(&block)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ require 'gather_content/dsl/base'
2
+ require 'gather_content/config/elements/choice_radio'
3
+ require 'gather_content/dsl/option'
4
+ require 'gather_content/dsl/other_option'
5
+
6
+ module GatherContent
7
+ module DSL
8
+ class ChoiceRadio < Base
9
+ def initialize(tab)
10
+ @choice_radio = GatherContent::Config::Element::ChoiceRadio.new
11
+ super(tab, @choice_radio)
12
+ end
13
+
14
+ def option(&block)
15
+ dsl = GatherContent::DSL::Option.new(@choice_radio)
16
+ dsl.instance_eval(&block)
17
+ end
18
+
19
+ def other_option(&block)
20
+ dsl = GatherContent::DSL::OtherOption.new(@choice_radio)
21
+ dsl.instance_eval(&block)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ require 'gather_content/dsl/tab'
2
+
3
+ module GatherContent
4
+ module DSL
5
+ class Config
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def tab(&block)
11
+ dsl = GatherContent::DSL::Tab.new(@config)
12
+ dsl.instance_eval(&block)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ require 'gather_content/dsl/base'
2
+ require 'gather_content/config/elements/files'
3
+
4
+ module GatherContent
5
+ module DSL
6
+ class Files < Base
7
+ def initialize(tab)
8
+ super(tab, GatherContent::Config::Element::Files.new)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ require 'gather_content/config/elements/option'
2
+ require 'gather_content/config/elements/other_option'
3
+
4
+ module GatherContent
5
+ module DSL
6
+ class Option
7
+ def initialize(choice)
8
+ @option = GatherContent::Config::Element::Option.new
9
+ if choice.options.last.instance_of?(GatherContent::Config::Element::OtherOption)
10
+ choice.options.insert(-2, @option)
11
+ else
12
+ choice.options << @option
13
+ end
14
+ end
15
+
16
+ def name(name)
17
+ @option.name = name
18
+ end
19
+
20
+ def label(label)
21
+ @option.label = label
22
+ end
23
+
24
+ def selected(selected)
25
+ @option.selected = selected
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ require 'gather_content/config/elements/files'
2
+ require 'gather_content/config/elements/other_option'
3
+
4
+ module GatherContent
5
+ module DSL
6
+ class OtherOption < Option
7
+ def initialize(choice)
8
+ @option = GatherContent::Config::Element::OtherOption.new
9
+ choice.other_option = true
10
+ choice.options << @option
11
+ end
12
+
13
+ def value(value)
14
+ @option.value = value
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ require 'gather_content/config/elements/section'
2
+
3
+ module GatherContent
4
+ module DSL
5
+ class Section
6
+ def initialize(tab)
7
+ @section = GatherContent::Config::Element::Section.new
8
+ tab.elements << @section
9
+ end
10
+
11
+ def name(name)
12
+ @section.name = name
13
+ end
14
+
15
+ def title(title)
16
+ @section.title = title
17
+ end
18
+
19
+ def subtitle(subtitle)
20
+ @section.subtitle = subtitle
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,54 @@
1
+ require 'gather_content/config/tab'
2
+ require 'gather_content/dsl/text'
3
+ require 'gather_content/dsl/files'
4
+ require 'gather_content/dsl/choice_checkbox'
5
+ require 'gather_content/dsl/choice_radio'
6
+ require 'gather_content/dsl/section'
7
+
8
+ module GatherContent
9
+ module DSL
10
+ class Tab
11
+ def initialize(builder)
12
+ @tab = GatherContent::Config::Tab.new
13
+ builder.tabs << @tab
14
+ end
15
+
16
+ def label(label)
17
+ @tab.label = label
18
+ end
19
+
20
+ def name(name)
21
+ @tab.name = name
22
+ end
23
+
24
+ def hidden(hidden)
25
+ @tab.hidden = hidden
26
+ end
27
+
28
+ def text(&block)
29
+ dsl = GatherContent::DSL::Text.new(@tab)
30
+ dsl.instance_eval(&block)
31
+ end
32
+
33
+ def files(&block)
34
+ dsl = GatherContent::DSL::Files.new(@tab)
35
+ dsl.instance_eval(&block)
36
+ end
37
+
38
+ def choice_radio(&block)
39
+ dsl = GatherContent::DSL::ChoiceRadio.new(@tab)
40
+ dsl.instance_eval(&block)
41
+ end
42
+
43
+ def choice_checkbox(&block)
44
+ dsl = GatherContent::DSL::ChoiceCheckbox.new(@tab)
45
+ dsl.instance_eval(&block)
46
+ end
47
+
48
+ def section(&block)
49
+ dsl = GatherContent::DSL::Section.new(@tab)
50
+ dsl.instance_eval(&block)
51
+ end
52
+ end
53
+ end
54
+ end