togostanza 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +15 -0
  5. data/Appraisals +7 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +29 -0
  9. data/Rakefile +9 -0
  10. data/bin/togostanza +5 -0
  11. data/gemfiles/activesupport_3.x.gemfile +7 -0
  12. data/gemfiles/activesupport_3.x.gemfile.lock +99 -0
  13. data/gemfiles/activesupport_4.x.gemfile +7 -0
  14. data/gemfiles/activesupport_4.x.gemfile.lock +107 -0
  15. data/lib/togostanza/application.rb +43 -0
  16. data/lib/togostanza/cli.rb +81 -0
  17. data/lib/togostanza/markdown.rb +39 -0
  18. data/lib/togostanza/stanza/base.rb +71 -0
  19. data/lib/togostanza/stanza/expression_map.rb +44 -0
  20. data/lib/togostanza/stanza/markdown.rb +37 -0
  21. data/lib/togostanza/stanza/querying.rb +43 -0
  22. data/lib/togostanza/stanza.rb +15 -0
  23. data/lib/togostanza/version.rb +3 -0
  24. data/lib/togostanza.rb +8 -0
  25. data/public/assets/stanza.css +113 -0
  26. data/public/assets/stanza.js +36 -0
  27. data/spec/dummy/app.rb +8 -0
  28. data/spec/dummy/bar_stanza/help.md +1 -0
  29. data/spec/dummy/bar_stanza/lib/bar_stanza.rb +3 -0
  30. data/spec/dummy/bar_stanza/stanza.rb +5 -0
  31. data/spec/dummy/bar_stanza/template.hbs +1 -0
  32. data/spec/dummy/foo_stanza/help.md +1 -0
  33. data/spec/dummy/foo_stanza/lib/foo_stanza.rb +3 -0
  34. data/spec/dummy/foo_stanza/stanza.rb +9 -0
  35. data/spec/dummy/foo_stanza/template.hbs +1 -0
  36. data/spec/features/help_spec.rb +13 -0
  37. data/spec/features/listing_spec.rb +17 -0
  38. data/spec/features/rendering_spec.rb +13 -0
  39. data/spec/features/resource_spec.rb +11 -0
  40. data/spec/lib/togostanza/stanza/base_spec.rb +79 -0
  41. data/spec/spec_helper.rb +17 -0
  42. data/templates/provider/Gemfile.erb +3 -0
  43. data/templates/provider/config.ru.erb +6 -0
  44. data/templates/stanza/Gemfile.erb +3 -0
  45. data/templates/stanza/gemspec.erb +20 -0
  46. data/templates/stanza/help.md.erb +22 -0
  47. data/templates/stanza/lib.rb.erb +4 -0
  48. data/templates/stanza/stanza.rb.erb +5 -0
  49. data/templates/stanza/template.hbs.erb +17 -0
  50. data/togostanza.gemspec +37 -0
  51. data/views/index.haml +9 -0
  52. data/views/layout.haml +13 -0
  53. metadata +321 -0
@@ -0,0 +1,43 @@
1
+ require 'sparql/client'
2
+
3
+ module TogoStanza::Stanza
4
+ module Querying
5
+ MAPPINGS = {
6
+ togogenome: 'http://ep.dbcls.jp/sparql7',
7
+ uniprot: 'http://ep.dbcls.jp/sparql7',
8
+ go: 'http://ep.dbcls.jp/sparql7'
9
+ }
10
+
11
+ def query(endpoint, sparql)
12
+ client = SPARQL::Client.new(MAPPINGS[endpoint] || endpoint)
13
+
14
+ #Rails.logger.debug "SPARQL QUERY: \n#{sparql}"
15
+
16
+ client.query(sparql).map {|binding|
17
+ binding.each_with_object({}) {|(name, term), hash|
18
+ hash[name] = term.to_s
19
+ }
20
+ }
21
+ end
22
+
23
+ def uniprot_url_from_togogenome(gene_id)
24
+ # refseq の UniProt
25
+ # slr1311 の時 "http://purl.uniprot.org/refseq/NP_439906.1"
26
+ query(:togogenome, <<-SPARQL).first[:up]
27
+ PREFIX insdc: <http://insdc.org/owl/>
28
+ PREFIX idorg: <http://rdf.identifiers.org/database/>
29
+
30
+ SELECT DISTINCT ?up
31
+ FROM <http://togogenome.org/graph/refseq/>
32
+ WHERE {
33
+ ?s insdc:feature_locus_tag "#{gene_id}" .
34
+ ?s rdfs:seeAlso ?np .
35
+ ?s rdfs:seeAlso ?xref .
36
+ ?np rdf:type idorg:Protein .
37
+ BIND (STRAFTER(STR(?np), "ncbiprotein/") AS ?npid)
38
+ BIND (IRI(CONCAT("http://purl.uniprot.org/refseq/", ?npid)) AS ?up)
39
+ }
40
+ SPARQL
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,15 @@
1
+ require 'active_support/all'
2
+
3
+ module TogoStanza::Stanza
4
+ autoload :Base, 'togostanza/stanza/base'
5
+
6
+ class << self
7
+ def find(id)
8
+ "#{id.camelize}Stanza".constantize
9
+ end
10
+
11
+ def all
12
+ Base.descendants
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module TogoStanza
2
+ VERSION = '0.0.1'
3
+ end
data/lib/togostanza.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'togostanza/version'
2
+
3
+ module TogoStanza
4
+ autoload :Application, 'togostanza/application'
5
+ autoload :CLI, 'togostanza/cli'
6
+ autoload :Markdown, 'togostanza/markdown'
7
+ autoload :Stanza, 'togostanza/stanza'
8
+ end
@@ -0,0 +1,113 @@
1
+ @charset "UTF-8";
2
+
3
+ body {
4
+ background-color: transparent;
5
+ padding: 1px 2px 3px;
6
+ font-family: "Myriad Pro","Helvetica Neue",san-serif;
7
+ font-size: 16px;
8
+ line-height: 20px;
9
+ }
10
+ a {
11
+ color:#45b8cc;
12
+ }
13
+
14
+ ul, ol {
15
+ padding:0;
16
+ margin:0 0 0 16px;
17
+ }
18
+ dl {
19
+ margin: 0;
20
+ padding: 0;
21
+ }
22
+ dd {
23
+ margin: 0;
24
+ }
25
+ dt + dt, dd + dt,
26
+ dt + dd, dd + dd {
27
+ margin-top: 8px;
28
+ }
29
+
30
+
31
+ body > .table, body > div {
32
+ -webkit-border-radius: 4px;
33
+ -moz-border-radius: 4px;
34
+ border-radius: 4px;
35
+ -webkit-box-shadow: 0 2px 2px rgba(0,0,0,.2);
36
+ -moz-box-shadow: 0 2px 2px rgba(0,0,0,.2);
37
+ box-shadow: 0 2px 2px rgba(0,0,0,.2);
38
+ background-color: #fff;
39
+ }
40
+ body > .table + .table, body > .table + div,
41
+ body > div + .table, body > div + div {
42
+ margin-top: 5px;
43
+ }
44
+
45
+ body > div {
46
+ padding: 10px 20px;
47
+ }
48
+
49
+ body > .table {
50
+ border-style: solid;
51
+ border-color: rgba(0,0,0,0);
52
+ border-top-width: 5px;
53
+ border-bottom-width: 5px;
54
+ border-left-width: 0;
55
+ border-right-width: 0;
56
+ }
57
+ .table {
58
+ margin-bottom: 0;
59
+ word-break:break-all;
60
+ }
61
+ .table caption {
62
+ background-color: #8ac8d1;
63
+ text-align: left;
64
+ color: white;
65
+ font-size: 18px;
66
+ line-height: 22px;
67
+ height: 22px;
68
+ font-weight: bold;
69
+ padding: 10px 24px 4px;
70
+ margin: 0;
71
+ border-top-left-radius: 4px;
72
+ border-top-right-radius: 4px;
73
+ }
74
+ .table tr:before, .table tr:after {
75
+ content: "";
76
+ display: table-cell;
77
+ width: 20px;
78
+ }
79
+ .table thead th, .table thead td {
80
+ border-bottom: 1px solid #555;
81
+ }
82
+ .table th, .table td,
83
+ .table > tbody > th, .table > tbody > td {
84
+ padding: 10px 4px;
85
+ line-height: 20px;
86
+ text-align: left;
87
+ vertical-align: top;
88
+ border-top: 1px solid #9fadad;
89
+ }
90
+ .table > tr:first-child > th, .table > tr:first-child > td,
91
+ .table > tbody > tr:first-child > th, .table > tbody > tr:first-child > td {
92
+ border-top: none;
93
+ }
94
+ th > .table, td > .table {
95
+ margin: -10px -4px;
96
+ width: 100%;
97
+ }
98
+ th > .table > tbody > tr:before,
99
+ td > .table > tbody > tr:before,
100
+ th > .table > tbody > tr:after,
101
+ td > .table > tbody > tr:after {
102
+ content: none;
103
+ }
104
+ .table li + li {
105
+ margin-top: 4px;
106
+ }
107
+
108
+ pre {
109
+ background-color:#daf1f5;
110
+ border:1px solid #ccc;
111
+ border:1px solid rgba(0,0,0,0.15);
112
+ padding: 8px 16px;
113
+ }
@@ -0,0 +1,36 @@
1
+ jQuery(function($) {
2
+ var RE = /^data-stanza-(.+)/
3
+
4
+ $('[data-stanza]').each(function(index) {
5
+ var $this = $(this),
6
+ data = $this.data(),
7
+ params = {};
8
+
9
+ $.each(this.attributes, function(i, attr) {
10
+ var key = (RE.exec(attr.name) || [])[1]
11
+
12
+ if (key) {
13
+ params[key.replace('-', '_')] = attr.value;
14
+ }
15
+ });
16
+
17
+ var src = data.stanza + '?' + $.param(params);
18
+
19
+ $('<iframe></iframe>')
20
+ .attr({src: src, frameborder: 0})
21
+ .attr({id: 'stanza-frame-' + index})
22
+ .attr({name: 'stanza-frame-' + index})
23
+ .width(data.stanzaWidth || '100%')
24
+ .height(data.stanzaHeight)
25
+ .appendTo($this);
26
+ });
27
+
28
+ window.onmessage = function(e) {
29
+ var message = JSON.parse(e.data),
30
+ iframe = $('#' + message.id);
31
+
32
+ if (iframe.attr('style').search(/height/) === -1) {
33
+ iframe.height(message.height);
34
+ }
35
+ };
36
+ });
data/spec/dummy/app.rb ADDED
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift *Dir.glob(File.expand_path('../*_stanza/lib', __FILE__))
2
+
3
+ require 'togostanza'
4
+ require 'foo_stanza'
5
+ require 'bar_stanza'
6
+
7
+ class DummyApp < TogoStanza::Application
8
+ end
@@ -0,0 +1 @@
1
+ # Bar
@@ -0,0 +1,3 @@
1
+ require_relative '../stanza'
2
+
3
+ BarStanza.root = File.expand_path('../..', __FILE__)
@@ -0,0 +1,5 @@
1
+ class BarStanza < TogoStanza::Stanza::Base
2
+ property :name do
3
+ 'bar'
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ <p>hello from {{name}}</p>
@@ -0,0 +1 @@
1
+ # Foo
@@ -0,0 +1,3 @@
1
+ require_relative '../stanza'
2
+
3
+ FooStanza.root = File.expand_path('../..', __FILE__)
@@ -0,0 +1,9 @@
1
+ class FooStanza < TogoStanza::Stanza::Base
2
+ property :name do
3
+ 'foo'
4
+ end
5
+
6
+ resource :foo_resource do
7
+ {hello: 'world'}
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ <p>hello from {{name}}</p>
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Help' do
4
+ it 'should display FooStanza help' do
5
+ visit '/foo/help'
6
+ page.should have_css('h1', text: 'Foo')
7
+ end
8
+
9
+ it 'should display BarStanza help' do
10
+ visit '/bar/help'
11
+ page.should have_css('h1', text: 'Bar')
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Listing' do
4
+ before do
5
+ visit '/'
6
+ end
7
+
8
+ it 'show all stanzas' do
9
+ page.should have_text('foo')
10
+ page.should have_text('bar')
11
+ end
12
+
13
+ it 'show link to help page' do
14
+ page.should have_link('help', href: '/foo/help')
15
+ page.should have_link('help', href: '/bar/help')
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Rendering' do
4
+ it 'should render FooStanza correctly' do
5
+ visit '/foo'
6
+ page.should have_content('hello from foo')
7
+ end
8
+
9
+ it 'should render BarStanza correctly' do
10
+ visit '/bar'
11
+ page.should have_content('hello from bar')
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Resource' do
4
+ before do
5
+ visit '/foo/resources/foo_resource'
6
+ end
7
+
8
+ it do
9
+ page.should have_content('{"hello":"world"}')
10
+ end
11
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe TogoStanza::Stanza::Base do
4
+ describe '.property' do
5
+ let(:klass) { Class.new(TogoStanza::Stanza::Base) }
6
+
7
+ specify 'raise error when specify a value and block' do
8
+ expect {
9
+ klass.property :foo, 'bar' do
10
+ 'baz'
11
+ end
12
+ }.to raise_error(ArgumentError)
13
+ end
14
+
15
+ specify 'raise error when neither specify a value nor block' do
16
+ expect {
17
+ klass.property :foo
18
+ }.to raise_error(ArgumentError)
19
+ end
20
+
21
+ specify 'allow specify a falsy value' do
22
+ klass.property :foo, false
23
+
24
+ klass.properties[:foo].should == false
25
+ end
26
+ end
27
+
28
+ describe '#context' do
29
+ let :klass do
30
+ Class.new(TogoStanza::Stanza::Base) {
31
+ property :foo do
32
+ 'foo'
33
+ end
34
+
35
+ property :bar do |bar|
36
+ bar * 3
37
+ end
38
+
39
+ property :baz do
40
+ {
41
+ qux: 'quux'
42
+ }
43
+ end
44
+
45
+ property :foobar, 'foobar'
46
+
47
+ resource :do_not_evaluate do
48
+ raise
49
+ end
50
+ }
51
+ end
52
+
53
+ subject { klass.new(bar: 'bar').context }
54
+
55
+ its(:foo) { should == 'foo' }
56
+ its(:bar) { should == 'barbarbar' }
57
+ its(:baz) { should == {'qux' => 'quux'} }
58
+ its(:foobar) { should == 'foobar' }
59
+ end
60
+
61
+ describe '#resource' do
62
+ let :klass do
63
+ Class.new(TogoStanza::Stanza::Base) {
64
+ resource :foo do
65
+ 'foo'
66
+ end
67
+
68
+ resource :bar do |bar|
69
+ bar * 3
70
+ end
71
+ }
72
+ end
73
+
74
+ let(:stanza) { klass.new(bar: 'bar') }
75
+
76
+ specify { stanza.resource(:foo).should == 'foo' }
77
+ specify { stanza.resource(:bar).should == 'barbarbar' }
78
+ end
79
+ end
@@ -0,0 +1,17 @@
1
+ ENV['RACK_ENV'] ||= 'test'
2
+
3
+ require_relative 'dummy/app'
4
+
5
+ require 'capybara'
6
+
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ config.order = 'random'
13
+
14
+ config.include Capybara::DSL
15
+ end
16
+
17
+ Capybara.app = DummyApp
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'togostanza'
@@ -0,0 +1,6 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ map '/stanza' do
5
+ run TogoStanza::Application
6
+ end
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,20 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = '<%= file_name %>'
6
+ spec.version = '0.0.1'
7
+ spec.authors = ['TODO: Write your name']
8
+ spec.email = ['TODO: Write your email address']
9
+ spec.summary = %q{TODO: Write a short summary. Required.}
10
+ spec.description = %q{TODO: Write a longer description. Optional.}
11
+ spec.homepage = ''
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_runtime_dependency 'togostanza'
20
+ end
@@ -0,0 +1,22 @@
1
+ <%= title %>
2
+ <%= '=' * title.size %>
3
+
4
+ TODO: Write a stanza description
5
+
6
+ ## Parameters:
7
+
8
+ (* = required)
9
+
10
+ | Name | Description |
11
+ |------------------|-------------------------------------|
12
+ | *data-stanza-foo | TODO: Write a parameter description |
13
+
14
+ ## Sample:
15
+
16
+ ```html
17
+ <div data-stanza="<stanza url>"></div>
18
+ ```
19
+
20
+ The above `<div>` will automatically embed the following Stanza in your HTML page.
21
+
22
+ <div data-stanza="/stanza/<%= stanza_id %>"></div>
@@ -0,0 +1,4 @@
1
+ require 'togostanza'
2
+ require_relative '../stanza'
3
+
4
+ <%= class_name %>.root = File.expand_path('../..', __FILE__)
@@ -0,0 +1,5 @@
1
+ class <%= class_name %> < TogoStanza::Stanza::Base
2
+ property :greeting do
3
+ 'hello, world!'
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <title><%= title %></title>
6
+ {{#each css_uri}}
7
+ <link rel="stylesheet" href="{{this}}" />
8
+ {{/each}}
9
+ <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
10
+ <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.2.2/bootstrap.min.js"></script>
11
+ {{adjust_iframe_height_script}}
12
+ </head>
13
+
14
+ <body>
15
+ <h1>{{greeting}}</h1>
16
+ </body>
17
+ </html>
@@ -0,0 +1,37 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'togostanza/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'togostanza'
7
+ spec.version = TogoStanza::VERSION
8
+ spec.authors = ['Keita Urashima']
9
+ spec.email = ['ursm@esm.co.jp']
10
+ spec.summary = %q{Development tools of TogoStanza}
11
+ spec.homepage = ''
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_runtime_dependency 'activesupport'
20
+ spec.add_runtime_dependency 'flavour_saver'
21
+ spec.add_runtime_dependency 'haml'
22
+ spec.add_runtime_dependency 'hashie'
23
+ spec.add_runtime_dependency 'parallel'
24
+ spec.add_runtime_dependency 'redcarpet'
25
+ spec.add_runtime_dependency 'sinatra'
26
+ spec.add_runtime_dependency 'sinatra-contrib'
27
+ spec.add_runtime_dependency 'sparql-client'
28
+ spec.add_runtime_dependency 'thor'
29
+
30
+ spec.add_development_dependency 'appraisal'
31
+ spec.add_development_dependency 'bundler'
32
+ spec.add_development_dependency 'capybara'
33
+ spec.add_development_dependency 'rake'
34
+ spec.add_development_dependency 'rspec'
35
+
36
+ spec.required_ruby_version = '>= 1.9.3'
37
+ end
data/views/index.haml ADDED
@@ -0,0 +1,9 @@
1
+ %h2 List of Stanzas
2
+
3
+ %ul
4
+ - TogoStanza::Stanza.all.sort_by(&:id).each do |stanza|
5
+ %li
6
+ = stanza.id
7
+
8
+ != surround '(', ')' do
9
+ %a{href: path(stanza.id, :help)} help
data/views/layout.haml ADDED
@@ -0,0 +1,13 @@
1
+ !!!
2
+
3
+ %html
4
+ %head
5
+ %meta(charset='utf-8')
6
+ %title= @page_title || 'Stanza'
7
+ %link(rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.2.2/css/bootstrap.min.css')
8
+ %link(rel='stylesheet' href='/stanza/assets/stanza.css')
9
+ %script(src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.js')
10
+ %script(src='/stanza/assets/stanza.js')
11
+
12
+ %body
13
+ .container!~ yield