Module: HotGlue

Defined in:
lib/hot-glue.rb,
lib/hotglue/engine.rb,
lib/hotglue/version.rb,
lib/generators/hot_glue/hot_glue.rb,
app/helpers/hot_glue/controller_helper.rb,
lib/generators/hot_glue/layout/builder.rb,
lib/generators/hot_glue/install_generator.rb,
lib/generators/hot_glue/typeahead_generator.rb,
lib/generators/hot_glue/markup_templates/erb.rb,
lib/generators/hot_glue/markup_templates/base.rb,
lib/generators/hot_glue/nav_template_generator.rb,
lib/generators/hot_glue/dropzone_install_generator.rb,
lib/generators/hot_glue/typeahead_install_generator.rb,
lib/generators/hot_glue/direct_upload_install_generator.rb,
lib/generators/hot_glue/flash_notices_install_generator.rb,
lib/generators/hot_glue/set_search_interface_install_generator.rb

Defined Under Namespace

Modules: ControllerHelper, Layout, TemplateBuilders Classes: DirectUploadInstallGenerator, DropzoneInstallGenerator, Engine, ErbTemplate, Error, FlashNoticesInstallGenerator, InstallGenerator, NavTemplateGenerator, ScaffoldGenerator, SetSearchInterfaceInstallGenerator, TemplateBase, TypeaheadGenerator, TypeaheadInstallGenerator, Version

Class Method Summary collapse

Class Method Details

.derrive_reference_name(thing_as_string) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/hot-glue.rb', line 77

def self.derrive_reference_name(thing_as_string)
  assoc_class = eval(thing_as_string)

  if assoc_class.new.respond_to?("name")
    display_column = "name"
  elsif assoc_class.new.respond_to?("to_label")
    display_column = "to_label"
  elsif assoc_class.new.respond_to?("full_name")
    display_column = "full_name"
  elsif assoc_class.new.respond_to?("display_name")
    display_column = "display_name"
  elsif assoc_class.new.respond_to?("email")
    display_column = "email"
  end
  display_column
end

.optionalized_ternary(namespace: nil, target:, nested_set:, prefix: "", modifier: "", with_params: false, top_level: false, put_form: false, instance_last_item: false) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/hot-glue.rb', line 23

def self.optionalized_ternary(namespace: nil,
                              target:,
                              nested_set:,
                              prefix: "", # is this used
                              modifier: "",
                              with_params: false,
                              top_level: false,
                              put_form: false,
                              instance_last_item: false )
  instance_sym = top_level ? "@" : ""


  if nested_set.nil? || nested_set.empty?
    return modifier + "#{(namespace + '_') if namespace}#{prefix}#{target}_path" + (("(#{instance_sym}#{target})" if put_form) || "")

  else
    res = modifier + ((namespace + "_" if namespace) || "") + nested_set.collect{|x|
      x[:singular] + "_"
    }.join() + prefix + target + "_path" + (("(#{nested_set.collect{
      |x| instance_sym + x[:singular] }.join(",")
    }#{ put_form ? ',' + (instance_last_item ? "@" : instance_sym) + target : '' })") || "")

    res
  # else
  #   raise "optional nested set is deprecated"
    # copy the first item, make a ternery in this cycle, and recursively move to both the
    # is present path and the is optional path

    # nonoptional = nested_set[0].dup
    # nonoptional[:optional] = false
    # rest_of_nest = nested_set[1..-1]
    #
    # is_present_path = HotGlue.optionalized_ternary(
    #   namespace: namespace,
    #   target: target,
    #   modifier: modifier,
    #   top_level: top_level,
    #   with_params: with_params,
    #   put_form: put_form,
    #   nested_set: [nonoptional, *rest_of_nest])

    # is_missing_path = HotGlue.optionalized_ternary(
    #   namespace: namespace,
    #   target: target,
    #   modifier: modifier,
    #   top_level: top_level,
    #   with_params: with_params,
    #   put_form: put_form,
    #   nested_set: rest_of_nest  )
    #
    # return "#{is_present_path}"
  end
end

.to_camel_case(str) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/hot-glue.rb', line 12

def self.to_camel_case(str)
  words = str.split(/[^a-zA-Z0-9]/) # split by non-alphanumeric characters
  return '' if words.empty?

  first_word = words.first.downcase
  rest_words = words[1..-1].map { |w| w.capitalize }

  first_word + rest_words.join
end