easy_data3 0.0.2

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 (85) hide show
  1. data/.gitignore +9 -0
  2. data/.idea/EasyData.iml +11 -0
  3. data/.idea/encodings.xml +5 -0
  4. data/.idea/misc.xml +11 -0
  5. data/.idea/modules.xml +9 -0
  6. data/.idea/vcs.xml +7 -0
  7. data/Gemfile +6 -0
  8. data/README.md +44 -0
  9. data/Rakefile +12 -0
  10. data/bin/linked_data +5 -0
  11. data/easy_data.gemspec +28 -0
  12. data/lib/controllers/easy_datas_controller.rb +340 -0
  13. data/lib/data_models/RDFa.rb +100 -0
  14. data/lib/data_models/data_models.rb +74 -0
  15. data/lib/data_models/linked_data_graph.rb +80 -0
  16. data/lib/data_models/model_rdf.rb +344 -0
  17. data/lib/data_models/namespaces/cc.rb +36 -0
  18. data/lib/data_models/namespaces/cert.rb +33 -0
  19. data/lib/data_models/namespaces/dc.rb +87 -0
  20. data/lib/data_models/namespaces/dc11.rb +47 -0
  21. data/lib/data_models/namespaces/doap.rb +68 -0
  22. data/lib/data_models/namespaces/exif.rb +192 -0
  23. data/lib/data_models/namespaces/foaf.rb +93 -0
  24. data/lib/data_models/namespaces/geo.rb +35 -0
  25. data/lib/data_models/namespaces/http.rb +50 -0
  26. data/lib/data_models/namespaces/owl.rb +83 -0
  27. data/lib/data_models/namespaces/rdfs.rb +41 -0
  28. data/lib/data_models/namespaces/rsa.rb +35 -0
  29. data/lib/data_models/namespaces/rss.rb +38 -0
  30. data/lib/data_models/namespaces/sioc.rb +110 -0
  31. data/lib/data_models/namespaces/skos.rb +61 -0
  32. data/lib/data_models/namespaces/wot.rb +45 -0
  33. data/lib/data_models/namespaces/xhtml.rb +32 -0
  34. data/lib/data_models/namespaces/xsd.rb +77 -0
  35. data/lib/data_models/namespaces.rb +28 -0
  36. data/lib/easy_data/tasks.rb +137 -0
  37. data/lib/easy_data/templates/easy_datas/_data_publications.html.erb +28 -0
  38. data/lib/easy_data/templates/easy_datas/_footer.html.erb +5 -0
  39. data/lib/easy_data/templates/easy_datas/_linked_data_model.html.erb +19 -0
  40. data/lib/easy_data/templates/easy_datas/_linked_datas.html.erb +19 -0
  41. data/lib/easy_data/templates/easy_datas/_list_model_info.html.erb +23 -0
  42. data/lib/easy_data/templates/easy_datas/_list_properties.html.erb +24 -0
  43. data/lib/easy_data/templates/easy_datas/_list_properties_edit.html.erb +35 -0
  44. data/lib/easy_data/templates/easy_datas/_menu.html.erb +24 -0
  45. data/lib/easy_data/templates/easy_datas/_menu_custom.html.erb +18 -0
  46. data/lib/easy_data/templates/easy_datas/_model_attributes.html.erb +45 -0
  47. data/lib/easy_data/templates/easy_datas/_model_attributes_edit.html.erb +17 -0
  48. data/lib/easy_data/templates/easy_datas/_model_attributes_info.html.erb +24 -0
  49. data/lib/easy_data/templates/easy_datas/_settings.html.erb +33 -0
  50. data/lib/easy_data/templates/easy_datas/authenticate_user.html.erb +20 -0
  51. data/lib/easy_data/templates/easy_datas/custom_rdf.html.erb +28 -0
  52. data/lib/easy_data/templates/easy_datas/info_easy_data.html.erb +7 -0
  53. data/lib/easy_data/templates/easy_datas/show.html.erb +1 -0
  54. data/lib/easy_data/templates/easy_datas/show.xml.builder +18 -0
  55. data/lib/easy_data/templates/easy_datas/show_all.html.erb +1 -0
  56. data/lib/easy_data/templates/easy_datas/show_all.xml.builder +16 -0
  57. data/lib/easy_data/templates/easy_datas/view_settings.html.erb +32 -0
  58. data/lib/easy_data/templates/images/LogoEasyData.jpg +0 -0
  59. data/lib/easy_data/templates/images/bg_ft.png +0 -0
  60. data/lib/easy_data/templates/images/bg_link.jpg +0 -0
  61. data/lib/easy_data/templates/images/easy_data_logo.png +0 -0
  62. data/lib/easy_data/templates/images/lock.png +0 -0
  63. data/lib/easy_data/templates/images/loginBt.png +0 -0
  64. data/lib/easy_data/templates/images/login_bg.png +0 -0
  65. data/lib/easy_data/templates/images/logo_ft.png +0 -0
  66. data/lib/easy_data/templates/images/powerby.jpg +0 -0
  67. data/lib/easy_data/templates/images/rdf_icon.png +0 -0
  68. data/lib/easy_data/templates/images/rdf_icon_s.png +0 -0
  69. data/lib/easy_data/templates/images/shadow_menu.png +0 -0
  70. data/lib/easy_data/templates/layouts/easy_data_layout.html.erb +18 -0
  71. data/lib/easy_data/templates/rdf/request.xml.builder +1 -0
  72. data/lib/easy_data/templates/rdf/show.builder +1 -0
  73. data/lib/easy_data/templates/stylesheets/easy_data_style.css +62 -0
  74. data/lib/easy_data/version.rb +3 -0
  75. data/lib/easy_data.rb +107 -0
  76. data/lib/routes.rb +41 -0
  77. data/lib/tasks/testing_installation.rb +6 -0
  78. data/test/data_models_test.rb +11 -0
  79. data/test/rdfa_test.rb +18 -0
  80. data/test/unit/RDFa_test.rb +1 -0
  81. data/test/unit/data_models_test.rb +10 -0
  82. data/test/unit/linked_data_graph_test.rb +1 -0
  83. data/test/unit/model_rdf_test.rb +1 -0
  84. data/test/unit/namespaces_test.rb +2 -0
  85. metadata +172 -0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ lib/task/testing_installation.rb
6
+ bin/linked_data
7
+ init.rb
8
+ setup.rb
9
+ .rvmrc
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="inheritedJdk" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ <orderEntry type="library" scope="PROVIDED" name="haml (v3.0.25, RVM: ruby-1.9.2-p180 [easy_data]) [gem]" level="application" />
8
+ <orderEntry type="library" scope="PROVIDED" name="hpricot (v0.8.4, RVM: ruby-1.9.2-p180 [easy_data]) [gem]" level="application" />
9
+ </component>
10
+ </module>
11
+
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
4
+ </project>
5
+
data/.idea/misc.xml ADDED
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="DependencyValidationManager">
4
+ <option name="SKIP_IMPORT_STATEMENTS" value="false" />
5
+ </component>
6
+ <component name="ProjectResources">
7
+ <default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
8
+ </component>
9
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-1.9.2-p180 [easy_data]" project-jdk-type="RUBY_SDK" />
10
+ </project>
11
+
data/.idea/modules.xml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/EasyData.iml" filepath="$PROJECT_DIR$/.idea/EasyData.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
9
+
data/.idea/vcs.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
7
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in linked_data.gemspec
4
+ gemspec
5
+
6
+
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ Installation
2
+ --------------
3
+
4
+ In config/routes.rb at the end of routes declarations include:
5
+
6
+ EasyDataRouting.routes
7
+
8
+ <p>After, in [RAILS_HOME]/Rakefile copy this line:</p>
9
+
10
+ <pre><code> require "easy_data/tasks" </code></pre>
11
+
12
+ <p>At the end, execute the next task:</p>
13
+
14
+ <pre><code> rake easy_data:install RAILS_ENV=development </code></pre>
15
+
16
+
17
+ <p>To start with administration, you should assign at admin user:</p>
18
+
19
+ <pre><code> rake easy_data:add_user[user,pass] RAILS_ENV=development </code></pre>
20
+
21
+
22
+ Commandas and Query
23
+ --------------------
24
+
25
+ <p>To get all possibles querys and URI's offers use this url:</p>
26
+
27
+ <pre><code> http://[project_host]/list_models </code></pre>
28
+
29
+
30
+ <p>After, to get any information about any model or resource, used this url: </p>
31
+
32
+ <pre><code> http://[project_host]/foaf/[model]/[id][.format] </code></pre>
33
+
34
+ <ul>
35
+ <li>[model] = any model list in first url</li>
36
+ <li>[id] = to get any information with primary key</li>
37
+ <li>[format] = this is for advance users, get response in this format</li>
38
+ </ul>
39
+
40
+ Collaborations
41
+ ------------------
42
+
43
+ <p>If you want to collaborate on this project or have any ideas and would like to share, please email me at my email, all are welcome!</p>
44
+ <p><a href="mailto:jnillo9@gmail.com" title="jnillo's mail">jnillo9@gmail.com</a></p>
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'yard' #Documentation gem
4
+ require 'hpricot'
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'test'
11
+ t.pattern = 'test/*_test.rb'
12
+ end
data/bin/linked_data ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "lib/data_models/data_models"
4
+
5
+ puts DataModels.load_models
data/easy_data.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ require "easy_data/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "easy_data3"
8
+ s.version = EasyData::VERSION
9
+ s.authors = ["jnillo"]
10
+ s.email = ["jnillo9@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gem/easy_data"
12
+ s.summary = "Blau blau Easily publish the linked data data model of your project RoR"
13
+ s.description = "Easily publish the linked data data model of your project RoR 3.x"
14
+
15
+ s.rubyforge_project = "easy_data3"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files test/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ #gem dependencies:
23
+ #All is not necesary, only is for study his methods
24
+
25
+ s.add_dependency(%q<hpricot>, [">= 0.8.4"])
26
+ s.add_dependency(%q<haml>, [">= 3.0.0"])
27
+ s.add_dependency(%q<rails>, ["> 3.0.0"])
28
+ end
@@ -0,0 +1,340 @@
1
+ require "action_controller"
2
+ require "action_view"
3
+ require "builder"
4
+
5
+ class EasyDatasController < ActionController::Base
6
+
7
+ layout 'easy_data_layout'
8
+
9
+ before_filter :authenticated, :only => [:custom_rdf]
10
+
11
+ def show
12
+ begin
13
+ model = (eval params[:model].to_s)
14
+
15
+ conditions = parser_params(params)
16
+
17
+ rdf = ModelRdf.new
18
+
19
+ no_valid = lambda{|c| c.nil?||c.empty?}
20
+
21
+ @reply = model.find :all, :conditions => {:id => params[:id]}
22
+
23
+ unless @reply.nil?
24
+ @host="http://"+request.env["HTTP_HOST"]
25
+
26
+ @rdf_model = rdf.get_model_rdf(@reply,params[:model],"http://"+request.env["HTTP_HOST"])
27
+ end
28
+
29
+ @xml = Builder::XmlMarkup.new
30
+
31
+ if no_valid.call(@rdf_model[:header]) || @reply.nil? # If the URI not available or data no publicated
32
+ render :nothing => true, :status => 400
33
+ else
34
+ respond_to do |format|
35
+ format.html
36
+ format.xml # render :template => "/rdf/request.xml.builder"
37
+ end
38
+ end
39
+ rescue
40
+ render :nothing => true, :status => 404
41
+ end
42
+ end
43
+
44
+ def show_all
45
+ begin
46
+ model = eval params[:model].to_s
47
+
48
+ rdf = ModelRdf.new
49
+
50
+ no_valid = lambda{|c| c.nil?||c.empty?}
51
+
52
+ @reply = model.find :all || nil
53
+
54
+ @host="http://"+request.env["HTTP_HOST"]
55
+
56
+ @rdf_model = rdf.get_model_rdf(@reply,params[:model],"http://"+request.env["HTTP_HOST"])
57
+
58
+ @xml = Builder::XmlMarkup.new
59
+
60
+ if no_valid.call(@rdf_model[:header]) || @reply.nil? # If the URI not available or data no publicated
61
+ render :nothing => true, :status => 404
62
+ else
63
+ respond_to do |format|
64
+ format.html
65
+ format.xml # render :template => "/rdf/request.xml.builder"
66
+ end
67
+ end
68
+ rescue
69
+ render :nothing => true, :status => 404
70
+ end
71
+ end
72
+
73
+ # Show information about data publications
74
+ #
75
+ #
76
+ def info_easy_data
77
+ rdf = ModelRdf.new
78
+ models = rdf.get_not_hidden_models
79
+ @list = []
80
+ @settings ||= YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml"))
81
+
82
+ models.each do |mod|
83
+ @list << "#{mod.gsub("::","_")}"
84
+ end
85
+
86
+ respond_to do |format|
87
+ format.html
88
+ format.xml
89
+ end
90
+ end
91
+
92
+ # Information about access to publicated data
93
+ def access_to_data
94
+ end
95
+
96
+ # Generate Linked Data Graph
97
+ def linked_data
98
+ end
99
+
100
+ # FAQ
101
+ def faq
102
+ end
103
+
104
+ def custom_rdf
105
+ @models = DataModels.load_models
106
+ @settings ||= YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml"))
107
+ end
108
+
109
+ def model_attributes
110
+
111
+ rdf = ModelRdf.new
112
+ @model_attributes = rdf.get_attributes_model(params[:model])
113
+ @model = params[:model]
114
+
115
+ render :partial => "model_attributes",:layout => nil
116
+ end
117
+
118
+ def model_attributes_edit
119
+
120
+ rdf = ModelRdf.new
121
+
122
+ @model_attributes = rdf.get_attributes_model(params[:model])
123
+ @model = params[:model]
124
+ @namespaces = EasyData::RDF::Namespaces.list_form
125
+
126
+ render :partial => "model_attributes_edit",:layout => nil
127
+
128
+ end
129
+
130
+ def model_attributes_info
131
+ rdf = ModelRdf.new
132
+
133
+ @model_attributes = rdf.get_attributes_model(params[:model])
134
+ @model = params[:model]
135
+
136
+ render :partial => "model_attributes_info",:layout => nil
137
+ end
138
+
139
+ def load_properties
140
+
141
+ unless params[:id] == ""
142
+ namespace = "EasyData::RDF::#{params[:id].upcase}"
143
+
144
+ rdf = ModelRdf.new
145
+
146
+ @namespace = params[:id]
147
+ @model_attributes = rdf.get_attributes_model(params[:model])
148
+
149
+ properties = (eval namespace).properties_form
150
+
151
+ if params[:attribute]!=params[:model]
152
+ render :inline => "<span>Property:</span><%= select type+'_property',attribute,properties,{:prompt => 'Select a property...'} -%><span class='rdf_info'>(Current value: <%= current_value%>)</span>",
153
+ :locals => {:properties => properties,
154
+ :type => params[:type],
155
+ :attribute => params[:attribute],
156
+ :current_value => @model_attributes[params[:type]][params[:attribute]][:property]}
157
+ else
158
+ render :inline => "<span>Property:</span><%= select 'property',attribute,properties,{:prompt => 'Select a property...'} -%><span class='rdf_info'>(Current value: <%= current_value%>)</span><br />",
159
+ :locals => {:properties => properties,
160
+ :attribute => params[:model],
161
+ :current_value => @model_attributes[:property]}
162
+
163
+ end
164
+ else
165
+ render :inline => ""
166
+ end
167
+ end
168
+
169
+ def load_linked_data_graph
170
+ if params[:model]
171
+ @model = params[:model]
172
+ @associations = ModelRdf.new.get_associations_model(@model)
173
+ @host = "http://"+request.env["HTTP_HOST"]
174
+ render :partial => "linked_data_model"
175
+ else
176
+ rdf = ModelRdf.new
177
+ models = []
178
+ DataModels.load_models.each do |mod|
179
+ unless rdf.hidden?(mod)
180
+ models << mod
181
+ end
182
+ end
183
+ @list = []
184
+ models.each do |mod|
185
+ @list << "#{mod.gsub("::","_")}"
186
+ end
187
+
188
+ render :partial => "linked_datas",:layout => nil
189
+ end
190
+ end
191
+
192
+ def custom_attributes
193
+
194
+ rdf = ModelRdf.new
195
+ @model = params[:model]
196
+
197
+ params["rdf_type_attributes"].each do |att,value|
198
+ rdf.update_attributes_model(params[:model],att,'namespace',value) if value != ""
199
+ if params["attributes_property"] && !params["attributes_property"][att].nil?
200
+ rdf.update_attributes_model(params[:model],att,'property',params["attributes_property"][att])
201
+ end
202
+ rdf.update_attributes_model(params[:model],att,'privacy',params[:privacy][att])
203
+ end
204
+
205
+
206
+ params["rdf_type_associations"].each do |assoc,value|
207
+
208
+ if value != ""
209
+ rdf.update_associations_model(params[:model],assoc,'namespace',value)
210
+ end
211
+ if params["associations_property"] && params["associations_property"][assoc]
212
+ rdf.update_associations_model(params[:model],assoc,'property',params["associations_property"][assoc])
213
+ end
214
+ rdf.update_associations_model(params[:model],assoc,'privacy',params[:privacy][assoc])
215
+
216
+ end
217
+
218
+
219
+ rdf.update_model(params[:model],"privacy",params[:privacy][params[:model]]) if params[:privacy][params[:model]]
220
+
221
+ if params[:property]
222
+ rdf.update_model(params[:model],"namespace",params[:namespace][params[:model]])
223
+ rdf.update_model(params[:model],"property",params[:property][params[:model]])
224
+ end
225
+
226
+ rdf.save
227
+
228
+ @model_attributes = rdf.get_attributes_model(@model)
229
+
230
+ render :partial => "model_attributes",:layout => nil
231
+ end
232
+
233
+ def view_settings
234
+ @settings ||= YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml"))
235
+ render :template => "easy_datas/view_settings", :layout => false
236
+ end
237
+
238
+ def settings
239
+ @settings ||= YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml"))
240
+ @images = Dir["#{RAILS_ROOT}/public/images/*"].map{|img| [img.gsub("#{RAILS_ROOT}/public/images/",""),img.gsub("#{RAILS_ROOT}/public/images/","")]}
241
+ render :partial => "settings",:layout => nil
242
+ end
243
+
244
+ def custom_settings
245
+ @settings = YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml"))
246
+
247
+ if !params["project"]["project"].empty? && params["project"]["project"]!=@settings["project"]["name"]
248
+ @settings["project"]["name"] = params["project"]["project"]
249
+ end
250
+
251
+ if !params["project"]["logo"].empty? && params["project"]["logo"]!=@settings["project"]["logo"]
252
+ @settings["project"]["logo"] = params["project"]["logo"]
253
+ end
254
+
255
+ if !params["project"]["description"].empty? && params["project"]["description"]!=@settings["project"]["description"]
256
+ @settings["project"]["description"] = params["project"]["description"]
257
+ end
258
+
259
+ if !params["project"]["email"].empty? && params["project"]["email"]!=@settings["project"]["contact_email"]
260
+ @settings["project"]["contact_email"] = params["project"]["email"]
261
+ end
262
+
263
+ if !params["user_admin"]["user"].empty? && !params["user_admin"]["pass"].empty?
264
+ (@settings["user_admin"]["user"] = params["user_admin"]["user"]) if @settings["user_admin"]["user"]!=params["user_admin"]["user"]
265
+ (@settings["user_admin"]["pass"] = params["user_admin"]["pass"]) if @settings["user_admin"]["pass"]!=params["user_admin"]["pass"]
266
+ end
267
+
268
+ (@settings["access"]["ip"] = params["access"]["ip"]) if params["access"]["ip"]!=@settings["access"]["ip"] && params["access"]["ip"]!= ""
269
+
270
+ save_settings(@settings)
271
+
272
+ render :template => "easy_datas/view_settings",:layout => false
273
+ end
274
+
275
+ def refresh_information
276
+ EasyData.refresh_information
277
+ redirect_to :action => "custom_rdf"
278
+ end
279
+
280
+ def authenticate_user
281
+ end
282
+
283
+ def login
284
+ @admin = YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml"))
285
+
286
+ if @admin["user_admin"]["user"] == params[:nick] && @admin["user_admin"]["password"] == params[:pass]
287
+ @current_user = params[:nick]
288
+ session[:easy_data_session] = params[:nick]
289
+ redirect_to :action => "custom_rdf"
290
+ else
291
+ redirect_to :authenticate_user
292
+ end
293
+ end
294
+
295
+ def logout
296
+ @current_user = nil
297
+ session[:easy_data_session]=nil if !session[:easy_data_session].nil?
298
+ redirect_to :action => "authenticate_user"
299
+ end
300
+
301
+ private
302
+
303
+ # Extract all parameters to build the query.
304
+ # @param [Hash] request's parameters
305
+ # @return [Hahs] Conditions hash
306
+ def parser_params (parameters = nil)
307
+
308
+ conditions = {}
309
+
310
+ if !parameters.empty?
311
+ parameters.each do |key,value| #Delete all elements that aren't need to query
312
+ unless ["controller","action","method","format","model"].include?key
313
+ conditions[key.to_sym] = value
314
+ end
315
+ end
316
+ end
317
+
318
+ return conditions
319
+
320
+ end
321
+
322
+ def authenticated
323
+ admin = YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml"))
324
+
325
+ if admin["access"]["ip"].nil? || admin["access"]["ip"].to_s == request.ip.to_s
326
+ if session[:easy_data_session].nil?
327
+ redirect_to :action => "authenticate_user"
328
+ end
329
+ else
330
+ render :nothing => true, :status => 404
331
+ end
332
+ end
333
+
334
+ def save_settings(settings)
335
+ file = File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml",'w')
336
+ file.puts YAML::dump(settings)
337
+ file.close
338
+ end
339
+
340
+ end
@@ -0,0 +1,100 @@
1
+ require "data_models/model_rdf"
2
+
3
+ class RDFa
4
+
5
+ ####################################
6
+ # HTML Tags
7
+ ####################################
8
+
9
+ #-----------------------------------------------Links
10
+ def a(model,href,value,attribute=nil,options=nil)
11
+ _html_code('a',model,value,attribute,"href='#{href||'#'}' "+options.to_s)
12
+ end
13
+
14
+ #-----------------------------------------------End Links
15
+ #-----------------------------------------------List_to_user
16
+ def ul(model,value,attribute=nil,options=nil)
17
+ _html_code_list('ul',model,value,options)
18
+ end
19
+
20
+ def ol(model,value,attribute=nil,options=nil)
21
+ _html_code_list('ol',model,value,options)
22
+ end
23
+ #-----------------------------------------------End List_to_user
24
+ #------------------------------------------------AUTO-CLOSED
25
+ def img(model,value,attribute=nil,options=nil)
26
+ _html_code('img',model,nil,attribute,"src='#{value||'#'}' "+options.to_s)
27
+ end
28
+
29
+ def input(model,type,attribute=nil,options=nil)
30
+ nil
31
+ end
32
+ #------------------------------------------------END AUTO-CLOSED
33
+
34
+ # This method is called if doesnt exist the method called by class's users
35
+ def method_missing(sym, *args, &block)
36
+ _html_code(sym.to_s,args[0],args[1],args[2],args[3])
37
+ end
38
+
39
+ #######################################
40
+ # Generate html code with RDFa info
41
+ #######################################
42
+ private
43
+
44
+ # This method generate a HTML tag with RDFa information included.
45
+ # @param [String] Html tag
46
+ # @param [String] Model's name
47
+ # @param [String] Tag content.
48
+ # @param [String] model's attribute
49
+ # @param [String] css and html tag options
50
+ # @return [String] Html tag with RDFa information
51
+ def _html_code(tag,model,value,attribute,options = "")
52
+ rdf_info = ModelRdf.new
53
+
54
+ if attribute.nil? #prefix + type_of
55
+ options = (options || "") + rdf_info.get_prefix(model)
56
+ options = options + rdf_info.model(model)
57
+ else #property
58
+ if attribute!=model
59
+ options = (options||"") + rdf_info.attribute(model,attribute)
60
+ else
61
+ options = (options||"") + rdf_info.model(model)
62
+ end
63
+ end
64
+
65
+ unless value.nil?
66
+ "<#{tag} #{options}>#{value}</#{tag}>"
67
+ else
68
+ "<#{tag} #{options}/>"
69
+ end
70
+ end
71
+
72
+ # This method generate a HTML list tag with RDFa information included.
73
+ # @param [String] Html tag
74
+ # @param [String] Model's name
75
+ # @param [String] Tag content
76
+ # @param [String] css and html tag options
77
+ # @return [String] Html list tag with RDFa information
78
+ def _html_code_list(tag,model,value,options = "")
79
+ rdf_info = ModelRdf.new
80
+
81
+ options = (options || "") + rdf_info.get_prefix(model)
82
+ options = options + rdf_info.model(model)
83
+
84
+ data_model = rdf_info.get_attributes_model(model)
85
+
86
+ html = "<#{tag} #{options}>"
87
+ unless value.nil?
88
+ data_model["attributes"].each do |att,info|
89
+ if info[:namespace] && info[:property]
90
+ html << "<li property='#{info[:namespace]}:#{info[:property]}'>#{value.attributes[att]}</li>"
91
+ end
92
+ end
93
+
94
+ html << "</#{tag}>"
95
+ end
96
+ html
97
+ end
98
+
99
+
100
+ end
@@ -0,0 +1,74 @@
1
+ module DataModels
2
+ # This method reads all models that the project hash.
3
+ # @return [Array] The proyect models list.
4
+ def self.load_models
5
+
6
+ models = [] #All models will be in this list.
7
+ models_valids = [] #This list is only to models with database table associated.
8
+ mod = nil
9
+
10
+ #Get all models in Model's folder
11
+ Dir["#{RAILS_ROOT}/app/models/**/*.rb"].each do |file|
12
+ models << file.gsub(RAILS_ROOT+'/app/models/',"").gsub('.rb','').classify
13
+ end
14
+
15
+ # Here, get the correct model's name: Singular or Plural
16
+ models.each do |model|
17
+ begin
18
+ mod = eval model
19
+ mod.columns
20
+ rescue
21
+ begin
22
+ mod = eval model.pluralize
23
+ mod.columns
24
+ rescue
25
+ mod = nil
26
+ end
27
+ end
28
+ if mod
29
+ models_valids << mod.to_s
30
+ end
31
+ end
32
+
33
+ models_valids
34
+ end
35
+
36
+ # This method return all model's attributes.
37
+ # @param [String] model's name
38
+ # @return [Array] model's attribute list.
39
+ def self.model_attributes(model)
40
+ model.columns.map{|att| att.name}.join(", ")
41
+ end
42
+
43
+ # This method return all model's relations
44
+ # @param [String] model's name
45
+ # @return [Hash] hash with all relations and relations type
46
+ def self.model_relations(model)
47
+
48
+ relations = {}
49
+
50
+ #Build the hash with relation name and relation's type.
51
+ model.reflections.each do |relation,values|
52
+ relations[relation] = {"model" => values.class_name,"type" => values.macro.to_s}
53
+ end
54
+
55
+ relations
56
+ end
57
+
58
+ # Return all RDF information stored in yaml file.
59
+ # @return [Hash] hash with all information stored in yaml file.
60
+ def self.build_models_yaml_file
61
+ self.models
62
+ end
63
+
64
+ # Return data model.
65
+ # @param [String] model's name
66
+ # @return [Hash] data model's information.
67
+ def self.get_model_data(model)
68
+ begin
69
+ eval model
70
+ rescue
71
+ eval model.pluralize
72
+ end
73
+ end
74
+ end