indexer 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,63 +0,0 @@
1
- module Indexer
2
-
3
- class Importer
4
-
5
- # Import metadata from a markdown source.
6
- #
7
- module MarkdownImportation
8
-
9
- #
10
- # Markdown import procedure.
11
- #
12
- def import(source)
13
- if File.file?(source)
14
- case File.extname(source)
15
- when '.md', '.markdown'
16
- load_markdown(source)
17
- return true
18
- end
19
- end
20
- super(source) if defined?(super)
21
- end
22
-
23
- #
24
- # Import metadata from HTML file.
25
- #
26
- def load_markdown(file)
27
- require 'nokogiri'
28
-
29
- text = File.read(file)
30
-
31
- begin
32
- require 'redcarpet'
33
- html = render_with_redcarpet(text)
34
- rescue LoadError
35
- require 'kramdown'
36
- html = render_with_kramdown(text)
37
- end
38
-
39
- doc = Nokogiri::HTML(html)
40
-
41
- load_html(doc)
42
- end
43
-
44
- #
45
- def render_with_redcarpet(text)
46
- renderer = Redcarpet::Render::HTML.new()
47
- markdown = Redcarpet::Markdown.new(renderer, :autolink=>true, :tables=>true, :space_after_headers=>true)
48
- markdown.render(text)
49
- end
50
-
51
- #
52
- def render_with_kramdown(text)
53
- Kramdown::Document.new(text).to_html
54
- end
55
-
56
- end
57
-
58
- # Include mixin into Importer class.
59
- include MarkdownImportation
60
-
61
- end
62
-
63
- end
@@ -1,167 +0,0 @@
1
- #require 'fileutils'
2
- #require 'tmpdir'
3
- require 'optparse'
4
- require 'json'
5
-
6
- require 'rack'
7
- require 'rack/server'
8
- require 'rack/handler'
9
- require 'rack/builder'
10
- require 'rack/directory'
11
- require 'rack/file'
12
-
13
- module Indexer
14
-
15
- module WebUI
16
-
17
- # Server is a Rack-based server that simply serves up the editing page.
18
- #
19
- class Server
20
-
21
- ROOT = File.join(File.dirname(__FILE__), 'webui')
22
-
23
- # Rack configuration file.
24
- #RACK_FILE = 'brite.ru'
25
-
26
- #
27
- #
28
- #
29
- def self.start(argv)
30
- new(argv).start
31
- end
32
-
33
- #
34
- # Server options, parsed from command line.
35
- #
36
- attr :options
37
-
38
- #
39
- # Setup new instance of Brite::Server.
40
- #
41
- def initialize(argv)
42
- @options = ::Rack::Server::Options.new.parse!(argv)
43
-
44
- @root = argv.first || Dir.pwd
45
-
46
- @options[:app] = app
47
- #@options[:pid] = "#{tmp_dir}/pids/server.pid"
48
-
49
- @options[:Port] ||= '4444'
50
- end
51
-
52
- # THINK: Should we be using a local tmp directory instead?
53
- # Then again, why do we need them at all, really?
54
-
55
- #
56
- # Temporary directory used by the rack server.
57
- #
58
- def tmp_dir
59
- @tmp_dir ||= File.join(Dir.tmpdir, 'indexer', root)
60
- end
61
-
62
- #
63
- # Start the server.
64
- #
65
- def start
66
- # ensure_site
67
-
68
- # create required tmp directories if not found
69
- # %w(cache pids sessions sockets).each do |dir_to_make|
70
- # FileUtils.mkdir_p(File.join(tmp_dir, dir_to_make))
71
- # end
72
-
73
- ::Rack::Server.start(options)
74
- end
75
-
76
- # # Ensure root is a Brite Site.
77
- # def ensure_site
78
- # return true if File.exist?(rack_file)
79
- # #return true if config.file
80
- # abort "Where's the site?"
81
- # end
82
-
83
- # # Load Brite configuration.
84
- # def config
85
- # @config ||= Brite::Config.new(root)
86
- # end
87
-
88
- #
89
- # Site root directory.
90
- #
91
- def root
92
- ROOT
93
- end
94
-
95
- # Configuration file for server.
96
- #def rack_file
97
- # RACK_FILE
98
- #end
99
-
100
- #
101
- # If the site has a `brite.ru` file, that will be used to start the server,
102
- # otherwise a standard Rack::Directory server ise used.
103
- #
104
- def app
105
- @app ||= (
106
- #if ::File.exist?(rack_file)
107
- # app, options = Rack::Builder.parse_file(rack_file, opt_parser)
108
- # @options.merge!(options)
109
- # app
110
- #else
111
- root = self.root
112
- json = index_json
113
-
114
- Rack::Builder.new do
115
- use IndexHTML, root
116
- map '/index' do
117
- run Proc.new{ |env| [200, {"Content-Type" => "text/json"}, [json]] }
118
- end
119
- run Rack::Directory.new("#{root}")
120
- end
121
- #end
122
- )
123
- end
124
-
125
- #
126
- #
127
- #
128
- def index_json
129
- YAML.load_file('.index').to_json
130
- end
131
-
132
- # Rack middleware to serve `index.html` file by default.
133
- #
134
- class IndexHTML
135
- def initialize(app, root)
136
- @app = app
137
- @root = root || Dir.pwd
138
- end
139
-
140
- def call(env)
141
- path = Rack::Utils.unescape(env['PATH_INFO'])
142
- index_file = File.join(@root, path, 'index.html')
143
- if File.exists?(index_file)
144
- [200, {'Content-Type' => 'text/html'}, File.new(index_file)]
145
- else
146
- @app.call(env) #Rack::Directory.new(@root).call(env)
147
- end
148
- end
149
- end
150
-
151
- #
152
- #def log_path
153
- # "_brite.log"
154
- #end
155
-
156
- #
157
- #def middleware
158
- # middlewares = []
159
- # #middlewares << [Rails::Rack::LogTailer, log_path] unless options[:daemonize]
160
- # #middlewares << [Rails::Rack::Debugger] if options[:debugger]
161
- # Hash.new(middlewares)
162
- #end
163
- end
164
-
165
- end
166
-
167
- end
@@ -1,41 +0,0 @@
1
-
2
- // Remove list items.
3
- $('body').delegate(".remove", "click", function() {
4
- var list = $(this).attr('list');
5
-
6
- //retrieve the context
7
- var context = ko.contextFor(this);
8
- var parentArray = context.$parent[list];
9
-
10
- //remove the data (context.$data) from the appropriate array on its parent (context.$parent)
11
- parentArray.remove(context.$data);
12
-
13
- return false;
14
- });
15
-
16
- // Add list items.
17
- $('body').delegate(".insert", "click", function() {
18
- var list = $(this).attr('list');
19
-
20
- //retrieve the context
21
- var context = ko.contextFor(this);
22
-
23
- var newItem = prompt("Enter new entry for " + list + ': ');
24
-
25
- if (newItem != '' && newItem != null) {
26
- context.$data[list].push(newItem);
27
- };
28
-
29
- return false;
30
- });
31
-
32
- //function save() {
33
- // $(). ko.toJSON(DotRubyViewModel);
34
- //}
35
-
36
- function save() {
37
- //var json = ko.toJSON(dotrubyInstance);
38
- var json = JSON.stringify( ko.toJS(dotrubyInstance), null, 2 );
39
- $('#lastSavedJson').val(json);
40
- };
41
-
@@ -1,203 +0,0 @@
1
- DotRuby = {
2
-
3
- viewModel: function(data) {
4
- var self = this;
5
- var data = DotRuby.prepareData(data);
6
-
7
- self.name = ko.observable(data.name);
8
- self.title = ko.observable(data.title);
9
- self.version = ko.observable(data.version);
10
- self.codename = ko.observable(data.codename);
11
- self.summary = ko.observable(data.summary);
12
- self.description = ko.observable(data.description);
13
- self.created = ko.observable(data.created);
14
- self.date = ko.observable(data.date);
15
- self.organization = ko.observable(data.organization);
16
- self.suite = ko.observable(data.suite);
17
- self.install_message = ko.observable(data.install_message);
18
-
19
- self.authors = ko.observableArray(data.authors);
20
- self.repositories = ko.observableArray(data.repositories);
21
- self.requirements = ko.observableArray(data.requirements);
22
- self.dependencies = ko.observableArray(data.dependencies);
23
- self.conflicts = ko.observableArray(data.conflicts);
24
- self.alternatives = ko.observableArray(data.alternatives);
25
- self.resources = ko.observableArray(data.resources);
26
- self.copyrights = ko.observableArray(data.copyrights);
27
- self.load_path = ko.observableArray(data.load_path);
28
-
29
- self.addResource = function(){
30
- this.resources.push(new DotRuby.resourceModel( {label: '', uri: ''} ));
31
- };
32
-
33
- self.addRepository = function(){
34
- this.repositories.push(new DotRuby.repositoryModel( {label: '', uri: '', scm: ''} ));
35
- };
36
-
37
- self.addRequirement = function(){
38
- this.requirements.push(new DotRuby.requirementModel( {name: '', version: '', development: false, groups: [], engines: [], platforms: []} ));
39
- };
40
-
41
- self.addDependency = function(){
42
- this.dependencies.push(new DotRuby.dependencyModel( {name: '', version: '', development: false, groups: [], engines: [], platforms: []} ));
43
- };
44
-
45
- self.addCopyright = function(){
46
- this.copyrights.push(new DotRuby.copyrightModel( {holder: '', year: '', license: ''} ));
47
- };
48
-
49
- self.addAuthor = function(){
50
- this.authors.push(new DotRuby.authorModel( {name: '', email: '', website: ''} ));
51
- };
52
-
53
- self.addAlternative = function(){
54
- this.alternatives.push('');
55
- };
56
-
57
- self.addConflict = function(){
58
- this.conflicts.push('');
59
- };
60
-
61
- self.addLoadpath = function(){
62
- this.load_path.push('');
63
- };
64
-
65
- self.json = function(){
66
- // @todo Convert resources back to mapping
67
- ko.toJSON(this)
68
- };
69
- },
70
-
71
- authorModel: function(data) {
72
- var self = this;
73
- self.name = ko.observable(data.name);
74
- self.email = ko.observable(data.email);
75
- self.website = ko.observable(data.website);
76
- self.roles = ko.observableArray(data.roles);
77
- },
78
-
79
- repositoryModel: function(data) {
80
- var self = this;
81
- self.label = ko.observable(data.label);
82
- self.uri = ko.observable(data.uri);
83
- self.scm = ko.observable(data.scm);
84
- },
85
-
86
- requirementModel: function(data) {
87
- var self = this;
88
- self.name = ko.observable(data.name);
89
- self.version = ko.observable(data.version);
90
- self.groups = ko.observableArray(makeArray(data.groups));
91
- self.platforms = ko.observableArray(makeArray(data.platforms));
92
- self.engines = ko.observableArray(makeArray(data.engines));
93
- self.development = ko.observable(data.development);
94
- self.repository = ko.observable(data.repository);
95
- },
96
-
97
- dependencyModel: function(data) {
98
- var self = this;
99
- self.name = ko.observable(data.name);
100
- self.version = ko.observable(data.version);
101
- self.groups = ko.observableArray(makeArray(data.groups));
102
- self.engines = ko.observableArray(makeArray(data.engines));
103
- self.platforms = ko.observableArray(makeArray(data.platforms));
104
- self.development = ko.observable(data.development);
105
- self.repository = ko.observable(data.repository);
106
- },
107
-
108
- resourceModel: function(data) {
109
- var self = this;
110
- self.label = ko.observable(data.label);
111
- self.uri = ko.observable(data.uri);
112
- },
113
-
114
- copyrightModel: function(data) {
115
- var self = this;
116
- self.holder = ko.observable(data.holder);
117
- self.year = ko.observable(data.year);
118
- self.license = ko.observable(data.license);
119
- },
120
-
121
- // take raw hash and convert elements to models
122
- // also ensure all fields are accounted for
123
- prepareData: function(data) {
124
- newData = {
125
- name: '',
126
- version: '0.0.0',
127
- date: '',
128
- title: '',
129
- organization: '',
130
- summary: '',
131
- description: '',
132
- requirements: [],
133
- dependencies: [],
134
- alternatives: [],
135
- repositories: [],
136
- resources: [],
137
- authors: [],
138
- copyrights: []
139
- };
140
-
141
- _.each(data, function(val, key){
142
- newData[key] = val;
143
- });
144
-
145
- newData.resources = _.map(data.resources, function(v,k){
146
- return(new DotRuby.resourceModel({'label': k, 'uri': v}));
147
- });
148
-
149
- newData.requirements = _.map(data.requirements, function(a){
150
- return(new DotRuby.requirementModel(a));
151
- });
152
-
153
- newData.dependencies = _.map(data.dependencies, function(a){
154
- return(new DotRuby.dependencyModel(a));
155
- });
156
-
157
- newData.repositories = _.map(data.repositories, function(x){
158
- return(new DotRuby.repositoryModel(x));
159
- });
160
-
161
- newData.authors = _.map(data.authors, function(x){
162
- return(new DotRuby.authorModel(x));
163
- });
164
-
165
- newData.copyrights = _.map(data.copyrights, function(x){
166
- return(new DotRuby.copyrightModel(x));
167
- });
168
-
169
- //newData.conflicts = _.map(data.conflicts, function(x){
170
- // return(new DotRuby.confictModel(x));
171
- //});
172
-
173
- //newData.alternatives = _.map(data.alternatives, function(x){
174
- // return(new DotRuby.copyrightModel(x));
175
- //});
176
-
177
- return newData;
178
- },
179
-
180
- };
181
-
182
- //DotRuby.resourceModel.create = function(){
183
- // return( new DotRuby.resourceModel({label: '', uri: ''}) );
184
- //};
185
-
186
- // support functions
187
-
188
- function makeArray(value){
189
- if (typeof(value) == Array) {
190
- return value;
191
- } else {
192
- return _.compact([value]);
193
- }
194
- };
195
-
196
- function makeString(value){
197
- if (typeof(value) == String) {
198
- return value;
199
- } else {
200
- return '' + value;
201
- }
202
- };
203
-