marfa 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 665b97268b20f6f5ec311e76c976713d9d39aca4
4
- data.tar.gz: 59c557ab53ff94ff31ca80ff35bf22c96846bdb6
3
+ metadata.gz: 47f3270a50621c8708d3977e3773b2ac5aa03516
4
+ data.tar.gz: 6a7512f056c10e4c2aabe283425dbf0756b72eeb
5
5
  SHA512:
6
- metadata.gz: 04f9a6f89afde128705cf3cdce767938c9e89e48ac30c78483eeb5b48cadca1a32d3d407dd2944cf1b49c204f61255f05a63411ead622ac95b4d80ce00249040
7
- data.tar.gz: 59f0e36adaa646598ee9871d9260d58398b9bca1bc5bc5e22530a8673b54547ba737001ccd4f461d1981eb9fd76054a6251c7cc0b93c358df4651ee951ab041f
6
+ metadata.gz: 8ec251c505738406677f431605eeb06a341d533fc7a2cec9567ee990f6c3948840392cbedd2c866ad237a90f8e35bab26519444da514b4571f2b9a64b27b35e8
7
+ data.tar.gz: 0219d83d38ebe1ce727dc73d42d5c1dcae9ddaf55685bad8f6af89e74a84dc4d2c8c071393a2224040e569b79acb836189e5aa0a039b1786f47e489b7ae09d01
data/Rakefile CHANGED
@@ -1,119 +1,14 @@
1
+ # Warning: this is deprecated and will be removed in 0.2
2
+ # TODO: remove in 0.2
3
+
1
4
  require 'fileutils'
2
5
  require 'rake'
3
6
  require 'babel/transpiler'
4
7
  require 'closure-compiler'
5
- # require 'sass/plugin'
6
- # require 'sass/engine'
7
- # require 'csso'
8
- include FileUtils
9
-
10
- # Default marfa configuration
11
- def create_marfa_config_file
12
- open('config/marfa.rb', 'w') do |file|
13
- file.puts '# Marfa configuration file'
14
- file.puts ''
15
- file.puts '# Specifying API Server is needed'
16
- file.puts "Marfa.config.api_server = ''"
17
- file.puts ''
18
- file.puts '# Views path is needed'
19
- file.puts "Marfa.config.views = File.expand_path('./app/views')"
20
- file.puts ''
21
- file.puts '# Cache config'
22
- file.puts "Marfa.config.cache = {"
23
- file.puts ' enabled: false,'
24
- file.puts " host: '',"
25
- file.puts ' port: 0,'
26
- file.puts ' db: 0,'
27
- file.puts ' expiration_time: 3600'
28
- file.puts '}'
29
- file.puts ''
30
- file.puts '# Static files content path'
31
- file.puts "Marfa.config.content_path = '/images/content/'"
32
- file.puts ''
33
- file.puts 'Marfa.config.cache_styles = true'
34
- file.puts ''
35
- file.puts '# Public folder'
36
- file.puts "Marfa.config.public_folder = File.expand_path('./static')"
37
- file.puts ''
38
- file.puts '# Static files cache'
39
- file.puts "Marfa.config.static_cache_control = [:public, :max_age => 2_592_000]"
40
- file.puts ''
41
- file.puts '# CSRF Protection'
42
- file.puts 'Marfa.config.csrf_enabled = false'
43
- file.puts ''
44
- file.puts '# HTML Compression'
45
- file.puts 'Marfa.config.html_compression_options = {'
46
- file.puts ':enabled => true,
47
- :remove_multi_spaces => true,
48
- :remove_comments => true,
49
- :remove_intertag_spaces => false,
50
- :remove_quotes => true,
51
- :compress_css => false,
52
- :compress_javascript => false,
53
- :simple_doctype => false,
54
- :remove_script_attributes => true,
55
- :remove_style_attributes => true,
56
- :remove_link_attributes => true,
57
- :remove_form_attributes => false,
58
- :remove_input_attributes => true,
59
- :remove_javascript_protocol => true,
60
- :remove_http_protocol => false,
61
- :remove_https_protocol => false,
62
- :preserve_line_breaks => false,
63
- :simple_boolean_attributes => true'
64
- file.puts '}'
65
- file.puts ''
66
- file.puts '# CSS Minifying'
67
- file.puts 'Marfa.config.minify_css = true'
68
- file.puts ''
69
- file.puts '# JS Minifying'
70
- file.puts 'Marfa.config.minify_js = true'
71
- end
72
- end
73
-
74
- def create_application_config_file
75
- open('config/application.rb', 'w') do |file|
76
- # file.puts "require 'marfa'"
77
- # file.puts ''
78
- end
79
- end
80
-
81
- # Default DTO file
82
- def create_base_dto_file
83
- open('app/models/dto.rb', 'w') do |file|
84
- file.puts "require 'marfa'"
85
- file.puts ''
86
- file.puts 'class DTO < Marfa::Models::BaseDTO'
87
- file.puts 'end'
88
- end
89
- end
90
-
91
- # Rackup file
92
- def create_rackup_config_file
93
- open('config.ru', 'w') do |file|
94
- file.puts "require 'marfa'"
95
- file.puts "require File.dirname(__FILE__) + '/app/bootstrap'"
96
- file.puts "require File.dirname(__FILE__) + '/config/marfa'"
97
- file.puts ''
98
- file.puts 'Marfa.configure_app'
99
- file.puts ''
100
- file.puts '# Controllers auto-bootstrap'
101
- file.puts "controllers = Object.constants.select { |c| c.to_s.include? 'Controller' }"
102
- file.puts 'controllers.map! { |controller| Object.const_get(controller) }'
103
- file.puts 'controllers += Marfa::Controllers.controllers_list'
104
- file.puts 'run Rack::Cascade.new(controllers)'
105
- end
106
- end
8
+ require 'marfa/file_templates'
107
9
 
108
- def create_bootstrap_file
109
- open('app/bootstrap.rb', 'w') do |file|
110
- file.puts "require File.dirname(__FILE__) + '/models/dto'"
111
- file.puts ''
112
- file.puts '# requiring all blocks and controllers'
113
- file.puts "Dir[File.dirname(__FILE__) + '/blocks/**/*.rb'].each { |file| require file }"
114
- file.puts "Dir[File.dirname(__FILE__) + '/controllers/**/*.rb'].each { |file| require file }"
115
- end
116
- end
10
+ include FileUtils
11
+ include Marfa::FileTemplates
117
12
 
118
13
  def js_transpile(path, is_plain_text = true)
119
14
  path = File.read(path) unless is_plain_text
@@ -121,47 +16,12 @@ def js_transpile(path, is_plain_text = true)
121
16
  result['code']
122
17
  end
123
18
 
124
- # def device_names
125
- # [
126
- # 'desktop',
127
- # 'smartphone',
128
- # 'tablet',
129
- # 'feature phone',
130
- # 'console',
131
- # 'tv',
132
- # 'car browser',
133
- # 'smart display',
134
- # 'camera',
135
- # 'portable media player',
136
- # 'phablet'
137
- # ]
138
- # end
139
-
140
- # Create styles
141
- # @param [String] scss_path - path to scss file
142
- # @param [String] device - device type
143
- # def create_style(scss_path, device)
144
- # dynamic_vars(device)
145
- # template = File.read(scss_path)
146
- # sass_engine = Sass::Engine.new(template, {syntax: :scss})
147
- # output = sass_engine.render
148
- # p output
149
- # Csso.optimize(output)
150
- # end
151
- #
152
- #
153
- # def dynamic_vars(device, section = 'root')
154
- # Sass::Plugin.options[:custom] ||= {}
155
- # Sass::Plugin.options[:custom][:device] = device
156
- # Sass::Plugin.options[:custom][:section] = section
157
- # # Sass::Plugin.options[:custom][:contentPath] = Marfa.config.content_path
158
- # end
159
-
160
19
  task :default do
161
20
  puts 'Please specify command'
162
21
  end
163
22
 
164
23
  task :start, [:home_path, :project_dir] do |t, args|
24
+ puts "Deprecation warning: this will be removed in marfa-0.2. Use marfa-start instead."
165
25
  project_dir = args[:project_dir]
166
26
 
167
27
  puts "Starting project #{project_dir}"
@@ -177,20 +37,21 @@ task :start, [:home_path, :project_dir] do |t, args|
177
37
  mkdir_p(%w(app config static app/blocks app/controllers app/models app/views))
178
38
  puts 'Project structure are created'
179
39
 
180
- puts 'Creating dummy model files...'
181
- create_base_dto_file
182
- puts 'Dummy model files are created'
183
-
184
40
  puts 'Creating config files...'
185
- create_marfa_config_file
186
- create_application_config_file
187
- create_bootstrap_file
188
- create_rackup_config_file
41
+
42
+ project_path = "#{args[:home_path]}/#{project_dir}"
43
+
44
+ marfa_rb(project_path)
45
+ application_rb(project_path)
46
+ bootstrap_rb(project_path)
47
+ config_ru(project_path)
48
+
189
49
  puts 'Config files are created'
190
50
  end
191
51
  end
192
52
 
193
53
  task :transpile_js, [:home_path, :search_dir, :output_dir] do |t, args|
54
+ puts "Deprecation warning: this will be removed in marfa-0.2. Use marfa-build-js instead."
194
55
  puts 'Starting js transpile'
195
56
 
196
57
  cd args[:home_path] + args[:search_dir], verbose: true
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ require 'optparse'
4
+ require 'babel/transpiler'
5
+ require 'closure-compiler'
6
+
7
+ include FileUtils
8
+
9
+ options = {
10
+ home_path: FileUtils.pwd,
11
+ search_dir: '',
12
+ output_dir: '/static/js'
13
+ }
14
+
15
+ parser = OptionParser.new do |opts|
16
+ opts.banner = 'Usage: marfa-build-js [options]'
17
+
18
+ opts.on('-s', '--search_dir search_dir', 'Search dir') do |search_dir|
19
+ options[:search_dir] = search_dir
20
+ end
21
+
22
+ opts.on('-o', '--output_dir output_dir', 'Output dir') do |output_dir|
23
+ options[:output_dir] = output_dir
24
+ end
25
+
26
+ opts.on('-h', '--help', 'Displays help') do
27
+ puts opts
28
+ exit
29
+ end
30
+ end
31
+
32
+ parser.parse!
33
+
34
+ puts 'Starting js transpile'
35
+
36
+ search_dir = options[:home_path] + options[:search_dir]
37
+
38
+ cd search_dir, verbose: true
39
+
40
+ Dir[search_dir + '/**/*.js'].each do |path|
41
+ puts "Processing #{path}"
42
+
43
+ closure = Closure::Compiler.new(
44
+ compilation_level: 'SIMPLE_OPTIMIZATIONS',
45
+ language_out: 'ES5_STRICT'
46
+ )
47
+
48
+ result = Babel::Transpiler.transform(File.read(path))
49
+ code = closure.compile(result['code'])
50
+ output_path = options[:home_path] + options[:output_dir]
51
+
52
+ mkdir_p(output_path) unless Dir.exist?(output_path)
53
+
54
+ File.open(output_path + '/' + path.split('/').last, 'w') do |f|
55
+ f.puts code
56
+ end
57
+ end
58
+
59
+ puts 'All js files processed'
data/bin/marfa-start ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ require 'optparse'
4
+ require 'marfa/file_templates'
5
+
6
+ include FileUtils
7
+ include Marfa::FileTemplates
8
+
9
+ options = {
10
+ home_path: FileUtils.pwd,
11
+ project_name: nil
12
+ }
13
+
14
+ parser = OptionParser.new do |opts|
15
+ opts.banner = 'Usage: marfa-start [project_name]'
16
+
17
+ opts.on('-n', '--name name', 'Project name') do |project_name|
18
+ options[:project_name] = project_name
19
+ end
20
+
21
+ opts.on('-h', '--help', 'Displays help') do
22
+ puts opts
23
+ exit
24
+ end
25
+ end
26
+
27
+ parser.parse!
28
+
29
+ if options[:project_name].nil?
30
+ print 'Enter project name: '
31
+ options[:project_name] = gets.chomp
32
+ end
33
+
34
+ project_name = options[:project_name]
35
+
36
+ puts "Starting project #{project_name}"
37
+ cd options[:home_path], verbose: true
38
+
39
+ unless Dir.exist?(project_name)
40
+ puts 'Creating project folder...'
41
+
42
+ mkdir_p(project_name)
43
+ cd project_name, verbose: true
44
+
45
+ puts 'Creating project structure...'
46
+ mkdir_p(%w(app config static app/blocks app/controllers app/models app/views))
47
+ puts 'Project structure are created'
48
+
49
+ puts 'Creating configuration files...'
50
+
51
+ project_path = "#{options[:home_path]}/#{project_name}"
52
+
53
+ marfa_rb(project_path)
54
+ application_rb(project_path)
55
+ bootstrap_rb(project_path)
56
+ config_ru(project_path)
57
+
58
+ puts 'Configuration files are created.'
59
+ puts "Project #{project_name} is created succesfully."
60
+ end
@@ -0,0 +1,113 @@
1
+ # This module contains file templates for generate new project structure
2
+ module Marfa
3
+ module FileTemplates
4
+ # generates content for 'config/application.rb' file
5
+ # @param [String] project_path - path to create_file
6
+ def application_rb(project_path)
7
+ File.open("#{project_path}/config/application.rb", 'w') do |file|
8
+ file.puts ''
9
+ end
10
+ end
11
+
12
+ # generates content for 'config/marfa.rb' file
13
+ # @param [String] project_path - path to create_file
14
+ def marfa_rb(project_path)
15
+ File.open("#{project_path}/config/marfa.rb", 'w') do |file|
16
+ file.puts "# Marfa configuration file
17
+
18
+ # Specifying API Server is needed
19
+ Marfa.config.api_server = ''
20
+
21
+ # Views path is needed
22
+ Marfa.config.views = File.expand_path('./app/views')
23
+
24
+ # Cache config
25
+ Marfa.config.cache = {
26
+ enabled: false,
27
+ host: '',
28
+ port: 0,
29
+ db: 0,
30
+ expiration_time: 3600
31
+ }
32
+
33
+ # Static files content path
34
+ Marfa.config.content_path = '/images/content/'
35
+
36
+ Marfa.config.cache_styles = true
37
+
38
+ # Public folder
39
+ Marfa.config.public_folder = File.expand_path('./static')
40
+
41
+ # Static files cache
42
+ Marfa.config.static_cache_control = [:public, max_age: 2_592_000]
43
+
44
+ # CSRF Protection
45
+ Marfa.config.csrf_enabled = false
46
+
47
+ # HTML Compression
48
+ Marfa.config.html_compression_options = {
49
+ enabled: true,
50
+ remove_multi_spaces: true,
51
+ remove_comments: true,
52
+ remove_intertag_spaces: false,
53
+ remove_quotes: true,
54
+ compress_css: false,
55
+ compress_javascript: false,
56
+ simple_doctype: false,
57
+ remove_script_attributes: true,
58
+ remove_style_attributes: true,
59
+ remove_link_attributes: true,
60
+ remove_form_attributes: false,
61
+ remove_input_attributes: true,
62
+ remove_javascript_protocol: true,
63
+ remove_http_protocol: false,
64
+ remove_https_protocol: false,
65
+ preserve_line_breaks: false,
66
+ simple_boolean_attributes: true
67
+ }
68
+
69
+ # CSS Minifying
70
+ Marfa.config.minify_css = true
71
+
72
+ # JS Minifying
73
+ Marfa.config.minify_js = true
74
+ "
75
+ end
76
+ end
77
+
78
+ # content for 'app/bootstrap.rb'
79
+ # @param [String] project_path - path to create_file
80
+ def bootstrap_rb(project_path)
81
+ File.open("#{project_path}/app/bootstrap.rb", 'w') do |file|
82
+ file.puts "require './config/application'
83
+
84
+ # requiring all blocks and controllers
85
+ Dir[File.dirname(__FILE__) + '/blocks/**/*.rb'].each { |file| require file }
86
+ Dir[File.dirname(__FILE__) + '/controllers/**/*.rb'].each { |file| require file }
87
+ "
88
+ end
89
+ end
90
+
91
+ # content for 'config.ru' file
92
+ # @param [String] project_path - path to create_file
93
+ def config_ru(project_path)
94
+ File.open("#{project_path}/config.ru", 'w') do |file|
95
+ file.puts "require 'marfa'
96
+ require File.dirname(__FILE__) + '/app/bootstrap'
97
+ require File.dirname(__FILE__) + '/config/marfa'
98
+
99
+ Marfa.configure_app
100
+
101
+ # Controllers auto-bootstrap
102
+ controllers = Object.constants.select { |c| c.to_s.include? 'Controller' }
103
+ controllers.map! { |controller| Object.const_get(controller) }
104
+ controllers += Marfa::Controllers.controllers_list
105
+
106
+ run Rack::Cascade.new(controllers)
107
+ "
108
+ end
109
+
110
+ end
111
+
112
+ end
113
+ end
data/lib/marfa/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Version constant
2
2
  module Marfa
3
3
  # The version constant for the current version of Marfa
4
- VERSION = '0.1.2' unless defined?(Marfa::VERSION)
4
+ VERSION = '0.1.4' unless defined?(Marfa::VERSION)
5
5
 
6
6
  # The current Marfa version.
7
7
  # @return [String] The version number
data/lib/marfa.rb CHANGED
@@ -15,6 +15,7 @@ require 'marfa/helpers/sass_functions'
15
15
  require 'marfa/models/base_dto'
16
16
  require 'marfa/models/api_model'
17
17
  require 'marfa/models/db_model'
18
+ require 'marfa/file_templates'
18
19
 
19
20
  # requires all submodules
20
21
  module Marfa
data/marfa.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'marfa'
6
- s.version = '0.1.2'
6
+ s.version = '0.1.4'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.date = Time.now.strftime('%Y-%m-%d')
9
9
  s.summary = 'Little Sinatra-based framework'
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.email = 'mvkrechetov@gmail.com'
13
13
  s.require_paths = ['lib']
14
14
  s.files = `git ls-files`.split("\n")
15
- s.executables = ['marfa']
15
+ s.executables = ['marfa', 'marfa-start', 'marfa-build-js']
16
16
  s.homepage = 'http://rubygems.org/gems/marfa'
17
17
  s.license = 'MIT'
18
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marfa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Krechetov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-03 00:00:00.000000000 Z
13
+ date: 2017-02-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: haml
@@ -254,6 +254,8 @@ description: Little Sinatra-based framework
254
254
  email: mvkrechetov@gmail.com
255
255
  executables:
256
256
  - marfa
257
+ - marfa-start
258
+ - marfa-build-js
257
259
  extensions: []
258
260
  extra_rdoc_files: []
259
261
  files:
@@ -261,6 +263,8 @@ files:
261
263
  - Gemfile
262
264
  - Rakefile
263
265
  - bin/marfa
266
+ - bin/marfa-build-js
267
+ - bin/marfa-start
264
268
  - lib/marfa.rb
265
269
  - lib/marfa/blocks/base_block.rb
266
270
  - lib/marfa/cache.rb
@@ -268,6 +272,7 @@ files:
268
272
  - lib/marfa/controllers.rb
269
273
  - lib/marfa/controllers/base_controller.rb
270
274
  - lib/marfa/controllers/css_controller.rb
275
+ - lib/marfa/file_templates.rb
271
276
  - lib/marfa/helpers/classes/string.rb
272
277
  - lib/marfa/helpers/controller.rb
273
278
  - lib/marfa/helpers/http/vary.rb