Added generators/templates to rmq command-line tool, such as:

rmq create controller foo
rmq create view foo_bar
This commit is contained in:
Todd Werth
2013-10-08 08:51:00 -07:00
parent 0414d6c7cd
commit fc15ff2ef2
14 changed files with 324 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
![RQM logo](http://ir_wp.s3.amazonaws.com/wp-content/uploads/sites/9/2013/07/rmq_logo.png)
# RubyMotionQuery - RMQ
A light, muggle, nonpolluting, jQuery-like library for [RubyMotion](http://rubymotion.com).
A fast, muggle, nonpolluting, jQuery-like library for [RubyMotion](http://rubymotion.com).
**The [RMQ Introductory Guide and other info][1] is a great place to start.**
@@ -46,8 +46,6 @@ Some of the code in RMQ came from BubbleWrap and Sugarcube. Not too much but som
- `bundle`
- `rake`
Adding `rmq_debug=true` to rake turns on some debugging features that are too slow or verbose to include in a normal build. It's great for normal use in the simulator, but you'll want to leave it off if you're measuring performance.
## Installation
RMQ **requires no other gems**. If you use stuff like **scale** and certain animations it will require some frameworks (like QuartzCore or CoreGraphics)
@@ -70,7 +68,7 @@ for **bleeding edge**, add this to your `Gemfile`:
git clone git@github.com:infinitered/rmq.git
cd rmq
rake rmq_debug=true
rake
The example app works in any orientation, on both iPhone and iPad. Notice how the benchmark popup is done with RMQ, then think about how you'd do that without it.
@@ -144,6 +142,33 @@ rmq(my_view).get
rmq(UILabel).get
```
### Command-line Tool
RMQ provides a command-line tool, mostly for generating files:
```
> rmq create my_app
```
Here are the commands available to you:
```
> rmq api
> rmq docs
> rmq create my_new_app
> rmq create model foo
> rmq create controller bar
> rmq create view foo_bar
> rmq create shared some_class_used_app_wide
> rmq create lib some_class_used_by_multiple_apps
# To test the create command without actually creating any files, do:
> rmq create view my_view dry_run
> rmq help
```
### Selectors
- Constant
@@ -577,6 +602,7 @@ The following are the only pollution in RMQ
- your_controller.rb
- your_other_controller.rb
- models
- shared
- stylers
- ui_view_styler.rb
- ui_button_styler.rb
@@ -585,14 +611,26 @@ The following are the only pollution in RMQ
- application_stylesheet.rb (inherit from RubyMotionQuery::Stylesheet)
- your_stylesheet.rb (inherit from ApplicationStylesheet)
- your_other_stylesheet.rb (inherit from ApplicationStylesheet)
- your_view_stylesheet.rb (module, included an any controller's stylesheet that needs it)
- views
- lib
- resource
- spec
- controllers
- lib
- models
- shared
- stylers
- views
### Debugging
Adding rmq_debug=true to rake turns on some debugging features that are too slow or verbose to include in a normal build. It's great for normal use in the simulator, but you'll want to leave it off if you're measuring performance.
```
rake rmq_debug=true
```
Use this to add your optional debugging code
```ruby
rmq.debugging?
=> true

134
bin/rmq
View File

@@ -1,37 +1,129 @@
#!/usr/bin/env ruby
unless ARGV.length > 0
puts 'RMQ - Invalid command, do something like this: rmq create my_new_app'
exit
require "erb"
class RmqCommandLine
HELP_TEXT = %{
Some things you can do with the rmq command:
> rmq api
> rmq docs
> rmq create my_new_app
> rmq create model foo
> rmq create controller foos
> rmq create view bar
> rmq create shared some_class_used_app_wide
> rmq create lib some_class_used_by_multiple_apps
# To test the create command without actually creating any files, do:
> rmq create view my_view dry_run
> rmq help }
class << self
VALID_CREATE_TYPES = [:model, :controller, :view, :shared, :lib]
def create(template_or_app_name, name, options)
@dry_run = true if options == 'dry_run'
if name
if VALID_CREATE_TYPES.include?(template_or_app_name.to_sym)
insert_from_template(template_or_app_name, name)
else
puts "RMQ - Invalid command, do something like this: rmq create controller my_controller\n"
end
else
create_app(template_or_app_name)
end
end
def create_app(app_name)
puts ' Creating app'
`motion create --template=git@github.com:infinitered/rmq-template.git #{app_name}`
puts %{
Complete. Things you should do:
> cd #{app_name}
> bundle
> rake spec
> rake
(main)> exit
Then try these:
> rake retina=3.5
> rake retina=4
> rake device_family=ipad
> rake device }
end
def insert_from_template(template_name, name)
puts "\n Creating #{template_name}: #{name}\n\n"
@template_dir = "#{Dir.pwd}/templates/#{template_name}/"
files = Dir["#{@template_dir}**/*"].select {|f| !File.directory? f}
@name = name.gsub(/(controller|stylesheet)/,'')
@name_camel_case = @name.split('_').map{|word| word.capitalize}.join
files.each do |template_file_path_and_name|
@in_app_path = File.dirname(template_file_path_and_name).gsub(@template_dir, '')
@ext = File.extname(template_file_path_and_name)
@file_name = File.basename(template_file_path_and_name, @ext)
@new_file_name = @file_name.gsub('name', @name)
@new_file_path_name = "#{Dir.pwd}/#{@in_app_path}/#{@new_file_name}#{@ext}"
#self.instance_variables.each{|var| puts "#{var} = #{self.instance_variable_get(var)}"}
if Dir.exist?(@in_app_path)
puts " Using existing directory: #{@in_app_path}"
else
puts " \u0394 Creating directory: #{@in_app_path}"
Dir.mkdir(@in_app_path) unless @dry_run
end
results = load_and_parse_erb(template_file_path_and_name)
if File.exists?(@new_file_path_name)
puts " X File exists, SKIPPING: #{@new_file_path_name}"
else
puts " \u0394 Creating file: #{@new_file_path_name}"
File.open(@new_file_path_name, 'w+') { |file| file.write(results) } unless @dry_run
end
end
puts "\n Done"
end
def load_and_parse_erb(template_file_name_and_path)
template_file = File.open(template_file_name_and_path, 'r').read
erb = ERB.new(template_file)
erb.result(binding)
end
end
end
# Process input, execute actions
unless ARGV.length > 0
puts "RMQ - Invalid command, do something like this: rmq create my_new_app\n"
puts RmqCommandLine::HELP_TEXT
exit
end
action = ARGV[0]
value = ARGV[1]
case action
when 'create'
`motion create --template=git@github.com:infinitered/rmq-template.git #{value}`
puts %{
Complete. Things you should do:
> cd #{value}
> bundle
> rake spec
> rake
(main)> exit
Then try these:
> rake retina=3.5
> rake retina=4
> rake device_family=ipad
> rake device }
RmqCommandLine.create(ARGV[1], ARGV[2], ARGV[3])
when 'api'
`open http://rdoc.info/github/infinitered/rmq`
when 'docs'
`open http://infinitered.com/rmq`
when 'help'
puts RmqCommandLine::HELP_TEXT
else
puts 'RMQ - Invalid action'
puts RmqCommandLine::HELP_TEXT
end

View File

@@ -0,0 +1,37 @@
class <%= @name_camel_case %>Controller < UIViewController
def viewDidLoad
super
rmq.stylesheet = <%= @name_camel_case %>ControllerStylesheet
rmq(self.view).apply_style :root_view
# Create your views here
end
# Remove if you are only supporting portrait
def supportedInterfaceOrientations
UIInterfaceOrientationMaskAll
end
# Remove if you are only supporting portrait
def willAnimateRotationToInterfaceOrientation(orientation, duration: duration)
rmq.all.reapply_styles
end
end
__END__
# You don't have to reapply styles to all UIViews, if you want to optimize,
# another way to do it is tag the views you need to restyle in your stylesheet,
# then only reapply the tagged views, like so:
def logo(st)
st.frame = {t: 10, w: 200, h: 96}
st.centered = :horizontal
st.image = image.resource('logo')
st.tag(:reapply_style)
end
# Then in willAnimateRotationToInterfaceOrientation
rmq(:reapply_style).reapply_styles

View File

@@ -0,0 +1,11 @@
class <%= @name_camel_case %>ControllerStylesheet < ApplicationStylesheet
def setup
# Add sytlesheet specific setup stuff here.
# Add application specific setup stuff in application_stylesheet.rb
end
def root_view(st)
st.background_color = color.white
end
end

View File

@@ -0,0 +1,9 @@
describe '<%= @name_camel_case %>Controller' do
before do
end
after do
end
end

View File

@@ -0,0 +1,4 @@
class <%= @name_camel_case %>
def initialize
end
end

View File

@@ -0,0 +1,9 @@
describe '<%= @name_camel_case %>' do
before do
end
after do
end
end

View File

@@ -0,0 +1,30 @@
class <%= @name_camel_case %>
def initialize(params = {})
end
def update(params = {})
self
end
def delete
end
def save
true
end
class << self
def create(params = {})
<%= @name_camel_case %>.new(params).tap do |<%= @name %>|
<%= @name %>.save
end
end
def find(id_or_params)
end
def all
<%= @name_camel_case %>.find(:all)
end
end
end

View File

@@ -0,0 +1,12 @@
describe '<%= @name_camel_case %>' do
before do
end
after do
end
it 'should create instance' do
<%= @name_camel_case %>.create.is_a?(<%= @name_camel_case %>).should == true
end
end

View File

@@ -0,0 +1,4 @@
class <%= @name_camel_case %>
def initialize
end
end

View File

@@ -0,0 +1,9 @@
describe '<%= @name_camel_case %>' do
before do
end
after do
end
end

View File

@@ -0,0 +1,10 @@
module <%= @name_camel_case %>Stylesheet
def <%= @name %>(st)
st.frame = {l: 5, t: 5, w: 80, h: 40}
st.background_color = color.light_gray
# Style overall view here
end
end

View File

@@ -0,0 +1,25 @@
class <%= @name_camel_case %> < UIView
def rmq_did_create(self_in_rmq)
self_in_rmq.tap do |q|
q.apply_style :<%= @name %>
# Add subviews here, like so:
#q.append(UILabel, :some_label)
end
end
end
# To style this view include its stylesheet at the top of each controller's
# stylesheet that is going to use it:
# class SomeStylesheet < ApplicationStylesheet
# include <%= @stylesheet_name %>
# Another option is to use your controller's stylesheet to style this view. This
# works well if only one controller uses it. If you do that, delete the
# view's stylesheet with:
# rm app/stylesheets/views/<%= @name %>.rb

View File

@@ -0,0 +1,9 @@
describe '<%= @name_camel_case %>' do
before do
end
after do
end
end