Module: PublishMyData::StripesHelper

Defined in:
app/helpers/publish_my_data/stripes_helper.rb

Instance Method Summary collapse

Instance Method Details

#additional_format(format, link) ⇒ Object



111
112
113
114
115
116
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 111

def additional_format(format, link)
  if (@additional_formats.nil?)
    @additional_formats = [];
  end
  @additional_formats.push({format:format, link:link})
end

#additional_formats_for_resource(uri) ⇒ Object



118
119
120
121
122
123
124
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 118

def additional_formats_for_resource(uri)
  format_options = {only_path:false, :uri => uri}
  additional_format('JSON', url_for(format_options.merge(format: 'json')))
  additional_format('RDF/XML', url_for(format_options.merge(format: 'rdf')))
  additional_format('Turtle', url_for(format_options.merge(format: 'ttl')))
  additional_format('N-triples', url_for(format_options.merge(format: 'nt')))
end

#badge(s) ⇒ Object



27
28
29
30
31
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 27

def badge(s)
   :div, :class => "pmd_badge badge_#{to_css_name(s)}" do
    s
  end      
end

#big_logoObject



103
104
105
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 103

def 
  image_tag(PublishMyData.logo_large)
end

#data_tab_nameObject



107
108
109
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 107

def data_tab_name
  "The Data"
end

#exclude_keys(hash, hash_to_exclude) ⇒ Object

returns the complement (by key) of hash_to_exclude in hash eg:

h = { "a" => 100, "b" => 400, "c" => 300  }
x = { "a" => 100, "b" => 40 }
puts exclude_keys(h,x))
$ {"c" => 300}


10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 10

def exclude_keys(hash, hash_to_exclude)
  unless (hash.nil?)
    unless (hash_to_exclude.nil?)
      hash.delete_if {|k,v| hash_to_exclude.include? k}
    else
        return hash
    end
  else
    return nil
  end
end

#fullwidth(&block) ⇒ Object



43
44
45
46
47
48
49
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 43

def fullwidth &block
  row do
    haml_tag "div", :class => 'pmd_box_full' do
      yield
    end
  end
end

#highlight_in_menu(str) ⇒ Object



55
56
57
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 55

def highlight_in_menu(str)
  @highlight_in_menu = str.downcase
end

#label(text) ⇒ Object



68
69
70
71
72
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 68

def label(text)
   :h5, :class => "pmd_phrase_label" do
    text
  end
end


126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 126

def link_to_sparql_tool_with_graph(graph_uri)
  sparql ="
    SELECT *
    WHERE {
        GRAPH <%{graph}> {
          ?s ?p ?o
        }
    }
    LIMIT 20"
  q = PublishMyData::SparqlQuery.new(sparql,:interpolations=>{:graph=>graph_uri})
  querystring = CGI.escape(q.query)
  link_to "(Open SPARQL tool at this graph)", "#{publish_my_data.sparql_endpoint_path}?&query=#{querystring}"
end

#logoObject



99
100
101
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 99

def 
  image_tag(PublishMyData.logo_small)
end


140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 140

def maybe_link_to_vocabulary(dataset, obj)
  # FIXME this is probably slow
  dataset.ontologies.each_with_index do |ontology, index|
    uris = ontology.classes.map(&:uri) + ontology.properties.map(&:uri)
    if uris.any?{|u| obj == u}
      return  :div do
         :small do
          "(Defined by ontology: #{link_to ontology.label || ontology.uri.to_s, resource_path_from_uri(ontology.uri)})".html_safe
        end
      end            
    end
  end

  dataset.concept_schemes.each_with_index do |concept_scheme, index|
    uris = concept_scheme.concepts.map(&:uri)
    if uris.any?{|u| obj == u}
      return  :div do
         :small do
          "(In concept scheme: #{link_to concept_scheme.label || concept_scheme.uri.to_s, resource_path_from_uri(concept_scheme.uri)})".html_safe
        end
      end            
    end
  end

  return 

end

#page_kind(kind_str) ⇒ Object



51
52
53
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 51

def page_kind(kind_str)
  @page_kind = kind_str
end

#page_title(text) ⇒ Object



74
75
76
77
78
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 74

def page_title(text)
   :h1 do
    text
  end      
end

#row(&block) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 33

def row &block
  capture_haml do
    haml_tag "div", :class => 'pmd_wrapper' do
      haml_tag "div", :class => 'pmd_row' do
        yield
      end
    end
  end
end

#section_title(text, show_icon = true) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 80

def section_title(text, show_icon = true)
  if (show_icon)
    linkname = to_css_name(text)
     :h2 do
      str = link_to ("#" + linkname).to_s, {id: linkname, class: 'pmd_bookmarkable', title: 'permalink to this section'} do
         :i, class: 'icon-bookmark' do
        end
      end
      str += text
      str
    end      
  else
     :h2 do
      text
    end
    
  end
end

#title_uri(uri) ⇒ Object



59
60
61
62
63
64
65
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 59

def title_uri(uri)      
  html_str = label 'URI'
  html_str +=  :h2, :class => "code click_to_select" do
    uri.to_s
  end
  html_str
end

#to_css_name(str) ⇒ Object



22
23
24
25
# File 'app/helpers/publish_my_data/stripes_helper.rb', line 22

def to_css_name(str)
  # convention for id and class names is underscore_case
  str.downcase.split(" ").join("_")
end