integrate Pixate into RubyMotion

This commit is contained in:
Watson
2013-01-03 09:12:45 +09:00
parent 544a34b2d9
commit c654671e99
5 changed files with 124 additions and 1 deletions

View File

@@ -1,4 +1,45 @@
RubyMotion-Pixate
=================
Pixate gem for RubyMotion.
Pixate gem for RubyMotion.
## Requirements
- RubyMotion 1.0 or greater (see http://www.rubymotion.com).
## Setup
1. Download the Pixate Framework package from http://www.pixate.com/ and copy the `PXEngine.framework` folder into `vendor` directory. Create the `vendor` directory if it does not exist. You should have something like this.
```
$ ls vendor/PXEngine.framework
/Headers/ PXEngine Resources/ Versions/
```
2. Edit the `Rakefile` of your RubyMotion project and add the following require lines.
```ruby
require 'rubygems'
require 'motion-pixate'
```
3. Still in the `Rakefile`, set up the `user`, `key` and `framework` variables in your application configuration block.
```ruby
Motion::Project::App.setup do |app|
# ...
app.pixate.user = 'USER ID'
app.pixate.key = 'KEY CODE'
app.pixate.framework = 'vendor/PXEngine.framework'
end
```
4. Create the `default.css` in `resources` directory.
## Usage
motion-pixate provides "style" method in REPL. You could change the stylesheet at the moment in REPL.
```
(main)> style "button { color : blue; }"
(main)> style "button { background-color: red; corner-radius: 20pt; }"
```

1
Rakefile Normal file
View File

@@ -0,0 +1 @@
require "bundler/gem_tasks"

1
lib/motion-pixate.rb Normal file
View File

@@ -0,0 +1 @@
require "motion/project/pixate"

View File

@@ -0,0 +1,63 @@
unless defined?(Motion::Project::Config)
raise "This file must be required within a RubyMotion project Rakefile."
end
class PixateConfig
attr_accessor :framework, :user, :key
def initialize(config)
@config = config
end
def framework=(path)
if @framework != path
@config.unvendor_project(@framework)
@framework = path
@config.vendor_project(path, :static, :products => ['PXEngine'], :headers_dir => 'Headers')
create_code
end
end
private
def create_code
unless @user && @key
raise "Need to configure `app.pixate.user' and `app.pixate.key' variables"
end
code = <<EOF
# This file is automatically generated. Do not edit.
PXEngine.licenseKey('#{@key}', forUser:'#{@user}')
def style(str)
PXStylesheet.styleSheetFromSource(str, withOrigin:0)
PXStylesheet.applyStylesheets
end
EOF
pixate_file = './app/pixate_code.rb'
create_stub(pixate_file, code)
add_file(pixate_file)
end
def create_stub(path, code)
if !File.exist?(path) or File.read(path) != code
File.open(path, 'w') { |io| io.write(code) }
end
end
def add_file(path)
files = @config.files.flatten
@config.files << path unless files.find { |x| File.expand_path(x) == File.expand_path(path) }
end
end
module Motion; module Project; class Config
variable :pixate
def pixate
@pixate ||= PixateConfig.new(self)
end
end; end; end

17
motion-pixate.gemspec Normal file
View File

@@ -0,0 +1,17 @@
# -*- encoding: utf-8 -*-
Version = "1.0"
Gem::Specification.new do |gem|
gem.name = "motion-pixate"
gem.version = Version
gem.authors = ['Paul Colton', 'Shizuo Fujita']
gem.email = ['paul@pixate.com', 'watson1978@gmail.com']
gem.description = 'Pixate integration for RubyMotion projects'
gem.summary = 'motion-pixate allows RubyMotion projects to easily embed the Pixate Framework.'
gem.homepage = 'https://github.com/Pixate/RubyMotion-Pixate'
gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
end