clearwater-roda 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5aa8a6d72425620e259a51f9b0bf48d092744bbf
4
+ data.tar.gz: 11ee3b36747c99c46cdc860e5a92c098bfa47571
5
+ SHA512:
6
+ metadata.gz: 4a5adf5cc6bb97edc91448ec367d955ddfc61190fdc437b465790146fb9a8f41c2508831663991fa7dbbb06dc684c143f396993fe3bb52dc82ada1aa3c0afea3
7
+ data.tar.gz: f9df03eba77c6e7af91d069f0fa85731e5c9cc780856befdcac3ec3aa599761d222f35874fb67c3bb6a33a89eeed802076067edfcce53bc77e525165c04352dc
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at jgaskins@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in clearwater-roda.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Clearwater::Roda
2
+
3
+ This gem helps you generate a Clearwater/Roda app from scratch.
4
+
5
+ ## Installation
6
+
7
+ $ gem install clearwater-roda
8
+
9
+ ## Usage
10
+
11
+ $ clearwater-roda new my_app
12
+
13
+ ## Development
14
+
15
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
16
+
17
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
18
+
19
+ ## Contributing
20
+
21
+ 1. Fork it
22
+ 1. Branch it
23
+ 1. Hack it
24
+ 1. Save it
25
+ 1. Commit it
26
+ 1. Push it
27
+ 1. Pull-request it
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/clearwater-rb/clearwater-roda. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "clearwater/roda"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'clearwater/roda/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "clearwater-roda"
8
+ spec.version = Clearwater::Roda::VERSION
9
+ spec.authors = ["Jamie Gaskins"]
10
+ spec.email = ["jgaskins@gmail.com"]
11
+
12
+ spec.summary = %q{Generate a Roda/Clearwater app from scratch}
13
+ spec.homepage = "https://github.com/clearwater-rb/clearwater-roda"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.12"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'clearwater/roda'
3
+
4
+ # If this grows beyond this simple app generator, may want to use something like
5
+ # Thor. But for now, this is all we really need.
6
+
7
+ command, app_name, _ = ARGV
8
+
9
+ usage = <<-USAGE
10
+ Usage:
11
+ $ clearwater-roda new APP_NAME'
12
+ # Generates a Clearwater/Roda app with the specified name.
13
+ $ clearwater-roda -v'
14
+ # Display version and exit
15
+ $ clearwater-roda -h'
16
+ # Display usage info
17
+ USAGE
18
+
19
+ case command
20
+ when 'new'
21
+ Clearwater::Roda.build_app app_name
22
+ when '-v'
23
+ puts Clearwater::Roda::VERSION
24
+ when '-h'
25
+ puts usage
26
+ else
27
+ warn usage
28
+ exit 1
29
+ end
@@ -0,0 +1,136 @@
1
+ require 'fileutils'
2
+
3
+ require 'clearwater/roda/template'
4
+
5
+ module Clearwater
6
+ module Roda
7
+ class Application
8
+ DirectoryAlreadyExists = Class.new(StandardError)
9
+
10
+ attr_reader :name
11
+
12
+ def initialize name
13
+ @name = name
14
+ @previous_dirs = []
15
+ end
16
+
17
+ def build
18
+ dir_must_not_exist!
19
+
20
+ mkdir
21
+ chdir
22
+ write_files
23
+ bundle
24
+ git_init
25
+ git_commit
26
+ chdir_back
27
+
28
+ puts
29
+ puts <<-EOF
30
+ Thanks for using Clearwater::Roda!
31
+
32
+ To run your new app:
33
+
34
+ $ cd #{dir_name}
35
+ $ ./dev
36
+
37
+ Then point your browser to http://localhost:9292/
38
+
39
+ The Clearwater app lives in #{Dir.pwd}/#{dir_name}/assets/js/app.rb. To compile
40
+ your assets for production, simply run:
41
+
42
+ $ rake assets:precompile
43
+
44
+ EOF
45
+ end
46
+
47
+ def mkdir
48
+ FileUtils.mkdir_p dir_name
49
+ end
50
+
51
+ def chdir
52
+ @previous_dirs.push Dir.pwd
53
+ FileUtils.chdir dir_name
54
+ end
55
+
56
+ def chdir_back
57
+ FileUtils.chdir @previous_dirs.pop
58
+ end
59
+
60
+ def bundle
61
+ system "bundle -j12"
62
+ end
63
+
64
+ def git_init
65
+ `git init`
66
+ end
67
+
68
+ def git_commit
69
+ `git add --all .`
70
+ `git commit -m 'Hello world!'`
71
+ end
72
+
73
+ def write_files
74
+ files = %W(
75
+ Gemfile
76
+ config.ru
77
+ assets/js/app.rb
78
+ dev
79
+ Rakefile
80
+ )
81
+
82
+ files.each do |template_name|
83
+ Template.new(
84
+ template_path(template_name),
85
+ template_name,
86
+ template_options,
87
+ ).write
88
+ end
89
+
90
+ app_filename = "#{underscore(name)}.rb"
91
+ Template.new(
92
+ template_path('app.rb'),
93
+ app_filename,
94
+ template_options,
95
+ ).write
96
+
97
+ FileUtils.chmod 0744, 'dev'
98
+ end
99
+
100
+ def template_options
101
+ {
102
+ underscored_name: dir_name,
103
+ titleized_name: class_name,
104
+ }
105
+ end
106
+
107
+ def template_path(name)
108
+ "#{File.expand_path('../../../../templates', __FILE__)}/#{name}"
109
+ end
110
+
111
+ def underscore name
112
+ name.gsub(/\w[A-Z]/) { |match| "#{match[0]}_#{match[1]}" }.downcase
113
+ end
114
+
115
+ def titleize name
116
+ name = name.gsub(/_[a-z]/) { |match| match[1].upcase }
117
+ name[0] = name[0].upcase
118
+ name
119
+ end
120
+
121
+ def dir_must_not_exist!
122
+ if File.exist? dir_name
123
+ raise DirectoryAlreadyExists, "directory #{dir_name} already exists!"
124
+ end
125
+ end
126
+
127
+ def class_name
128
+ titleize name
129
+ end
130
+
131
+ def dir_name
132
+ underscore name
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,34 @@
1
+ require 'fileutils'
2
+
3
+ module Clearwater
4
+ module Roda
5
+ class Template
6
+ attr_reader :input, :output, :options
7
+
8
+ def initialize input_filename, output_filename, options={}
9
+ @input = input_filename
10
+ @output = output_filename
11
+ @options = options
12
+ end
13
+
14
+ def write
15
+ if output.respond_to? :write
16
+ output.write content
17
+ else
18
+ FileUtils.mkdir_p File.dirname(output)
19
+ File.write output, content
20
+ end
21
+ end
22
+
23
+ def content
24
+ string = if input.respond_to? :read
25
+ input.read
26
+ else
27
+ File.read(input)
28
+ end
29
+
30
+ string % options
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module Clearwater
2
+ module Roda
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require 'clearwater/roda/version'
2
+ require 'clearwater/roda/application'
3
+
4
+ module Clearwater
5
+ module Roda
6
+ module_function
7
+
8
+ def build_app name
9
+ Application.new(name).build
10
+ end
11
+ end
12
+ end
data/templates/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'opal'
4
+ gem 'clearwater', '~> 1.0.0.rc4'
5
+ gem 'roda'
6
+ gem 'roda-opal_assets'
7
+
8
+ group :development do
9
+ gem 'rerun'
10
+ gem 'rake'
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'bundler/setup'
2
+ require 'opal'
3
+ require 'clearwater'
4
+ require 'roda/opal_assets'
5
+
6
+ # Keep a single asset compiler in case we want to use it for multiple tasks.
7
+ assets = Roda::OpalAssets.new(env: :production)
8
+
9
+ desc 'Precompile assets for production'
10
+ task 'assets:precompile' do
11
+ assets << 'app.js'
12
+ assets.build
13
+ end
data/templates/app.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'roda'
2
+ require 'roda/opal_assets'
3
+ require 'opal'
4
+ require 'clearwater'
5
+
6
+ class %{titleized_name} < Roda
7
+ plugin :public
8
+
9
+ assets = Roda::OpalAssets.new
10
+
11
+ route do |r|
12
+ r.public
13
+ assets.route r
14
+
15
+ <<-HTML
16
+ <!DOCTYPE html>
17
+ <html>
18
+ <head>
19
+ <meta charset="utf-8" />
20
+ <title>%{titleized_name}</title>
21
+ </head>
22
+
23
+ <body>
24
+ <div id="app"></div>
25
+ #{assets.js 'app.js'}
26
+ </body>
27
+ </html>
28
+ HTML
29
+ end
30
+ end
@@ -0,0 +1,125 @@
1
+ require 'opal'
2
+ require 'clearwater'
3
+
4
+ class Layout
5
+ include Clearwater::Component
6
+
7
+ def render
8
+ # Equivalent HTML:
9
+ # <div>
10
+ # <h1 class="heading">
11
+ # <a href="/">Hello, Clearwater</a>
12
+ # </h1>
13
+ # <nav>
14
+ # <a href="/foo">Foo</a>
15
+ # <a href="/bar">Bar</a>
16
+ # <a href="/bar/baz">Baz</a>
17
+ # </nav>
18
+ # <%%= outlet || HomePage.new.render %%>
19
+ # </div>
20
+ div([
21
+ h1({ class_name: 'heading' }, [
22
+ Link.new({ href: '/' }, 'Hello, Clearwater!'),
23
+ ]),
24
+ nav([
25
+ # The Link component is how you navigate between routes in Clearwater
26
+ # apps. This leaves the `a` helper method to do a typical hard link.
27
+ Link.new({ href: '/foo' }, 'Foo'),
28
+
29
+ # One of the nice things about defining your UI with code instead of
30
+ # markup is that adding whitespace doesn't look out of place.
31
+ ' ',
32
+ Link.new({ href: '/bar' }, 'Bar'),
33
+ ' ',
34
+ Link.new({ href: '/bar/baz' }, 'Baz'),
35
+ ]),
36
+
37
+ # The `outlet` method is a method for routing targets to render their
38
+ # child routes, similar to the same keyword in Ember.js templates. If
39
+ # there is no child route, we render a HomePage component.
40
+ outlet || HomePage.new,
41
+ ])
42
+ end
43
+ end
44
+
45
+ # This is our default homepage component. Note that in the Layout component, we
46
+ # render this by calling HomePage.new. This means we get a brand-new HomePage
47
+ # component each time we render, despite the Layout sticking around for the life
48
+ # of the app. Because of this, our HomePage cannot hold state and only knows
49
+ # about what it is told in its initialize method (which, in this case, is
50
+ # nothing).
51
+ class HomePage
52
+ include Clearwater::Component
53
+
54
+ def render
55
+ article([
56
+ h1('Welcome to Clearwater'),
57
+
58
+ p(<<-EOP),
59
+ Clearwater is a Ruby front-end framework.
60
+ EOP
61
+ ])
62
+ end
63
+ end
64
+
65
+ # We use a Struct here because it's shorthand for a class that takes an argument
66
+ # and gives us an accessor method with that name. Otherwise, it's identical to a
67
+ # typical template; we just wanted to take an argument.
68
+ ChildRoute = Struct.new(:name) do
69
+ include Clearwater::Component
70
+
71
+ def render
72
+ div([
73
+ h2(name),
74
+ p("This is the child route called #{name}"),
75
+
76
+ div([
77
+ h3('Child content:'),
78
+ outlet,
79
+ ]),
80
+ ])
81
+ end
82
+ end
83
+
84
+ router = Clearwater::Router.new do
85
+ # Routing targets are other components. They stick around for the life of the
86
+ # app, so they can store state or you can use them to fetch state from a data
87
+ # store somewhere else in your app.
88
+ #
89
+ # Syntax:
90
+ # route path_segment => target
91
+ # route another_segment => another_target do
92
+ # route
93
+ # end
94
+ route 'foo' => ChildRoute.new('foo')
95
+ route 'bar' => ChildRoute.new('bar') do
96
+ route 'baz' => ChildRoute.new('baz')
97
+ end
98
+ end
99
+
100
+ # The Clearwater app itself takes 3 args:
101
+ app = Clearwater::Application.new(
102
+ # The component is any component that includes the Clearwater::Component mixin
103
+ component: Layout.new,
104
+
105
+ # This is the router we created above. If you're not using routing, you can
106
+ # safely omit this.
107
+ router: router,
108
+
109
+ # This is any existing element on the page. Note that it has to exist already
110
+ # at this point, so unless you're delaying the execution of this script with
111
+ # DOM events, you'll need to put the script tag below the element you're
112
+ # rendering into. This is usually accomplished by putting the script tag at
113
+ # the bottom of the <body> element.
114
+ element: Bowser.document['#app'],
115
+ )
116
+
117
+ # Uncomment the following line to display timing information in the console on
118
+ # every render.
119
+ #
120
+ # app.debug!
121
+
122
+ # This adds the app to the Clearwater app registry (so it can be re-rendered on
123
+ # route changes) and triggers the first render. Subsequent renders should use
124
+ # app.render instead.
125
+ app.call
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require './%{underscored_name}'
3
+
4
+ $LOAD_PATH << 'lib'
5
+
6
+ run %{titleized_name}
data/templates/dev ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ bundle check || bundle -j12
4
+
5
+ rerun -i 'assets/**/*' 'rackup'
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clearwater-roda
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jamie Gaskins
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - jgaskins@gmail.com
58
+ executables:
59
+ - clearwater-roda
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - clearwater-roda.gemspec
73
+ - exe/clearwater-roda
74
+ - lib/clearwater/roda.rb
75
+ - lib/clearwater/roda/application.rb
76
+ - lib/clearwater/roda/template.rb
77
+ - lib/clearwater/roda/version.rb
78
+ - templates/Gemfile
79
+ - templates/Rakefile
80
+ - templates/app.rb
81
+ - templates/assets/js/app.rb
82
+ - templates/config.ru
83
+ - templates/dev
84
+ homepage: https://github.com/clearwater-rb/clearwater-roda
85
+ licenses: []
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.6.6
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Generate a Roda/Clearwater app from scratch
107
+ test_files: []