Code Monkey home page Code Monkey logo

hoop's Introduction

hoop

How to try ?

git clone [email protected]:0x73/hoop.git
shards install
crystal run example/webview_example.cr

Bundled Application

cd example/bundled_application && sh build.sh && open Hoop.app

Basic example

# app.cr

require "src/hoop"
include Hoop

NSAutoreleasePool.new
NSApp.activation_policy = LibAppKit::NSApplicationActivationPolicy::Regular
appName = "Hello, World !".to_objc

window = NSWindow.new(NSRect.new(0, 0, 700, 700).to_objc, LibAppKit::NSWindowMask::Titled, LibAppKit::NSBackingStoreType::Buffered, false)
window.set_background_color = NSColor.white_color.to_objc
window.cascade_top_left_from_point NSPoint.new(20, 20).to_objc
window.title = appName
window.make_key_and_order_front nil.to_objc

b = NSButton.new(NSRect.new(50, 50, 600, 100).to_objc)
b.set_title = "MAKE REQUEST"

class Foo < NSObject
  export_class
  def bar
	url = NSURL.url_with_string "https://jsonplaceholder.typicode.com/posts/2"
	req = NSURLRequest.request_with_url url.to_objc
	res = NSURLResponse.new

	data = NSURLConnection.send_synchronous_request req.to_objc, res.to_objc, nil.to_objc
	ns_log data

	result = NSJSONSerialization.json_object_with_data data.to_objc, LibCF::NSJSONReadingOptions::KNilOptions, nil.to_objc
	ns_log result

	userId = result.object_for_key("userId")
	id = result.object_for_key("id")
	title = result.object_for_key("title")
	body = result.object_for_key("body")

	ns_log "#{userId.as(NSNumber).intValue}"
	ns_log "#{id.as(NSNumber).intValue}"
	ns_log "#{title.as(NSString)}"
	ns_log "#{body}"

    alert = NSAlert.new
    alert.set_message_text = "User Id: #{userId.as(NSNumber).intValue} - Id: #{id.as(NSNumber).intValue} - Title: #{title} - Body: #{body}"
    alert.run_modal
  end
  export "bar"
end

b.target = Foo.new.to_objc
b.action = "bar"

window.content_view << b.to_objc
ns_log "app launched"

NSApp.activate_ignoring_other_apps = true
NSApp.run
$ crystal app.cr

Contributing

  1. Fork it ( https://github.com/hoopcr/hoop/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Authors

Thanks

Thanks to Manas for their awesome work on Crocoa.

hoop's People

Contributors

segecey avatar askn avatar isidentical avatar jhass avatar

Stargazers

Yasin ATEŞ avatar Juri Hahn avatar ik5 avatar ❂ avatar Rob avatar sonopictorial avatar Maximilian Stroh avatar AJ Bourg avatar E avatar Serhii Potapov avatar Chance Snow avatar Iain Moncrief avatar  avatar  avatar aligo avatar Ahmed Mohamed avatar Jack avatar Sergey Fedorov avatar Garden Yuen avatar Hasnat Babur avatar Nameer avatar Nils Martel avatar  avatar Jason Larsen avatar Ryan Shah avatar Max Lewin avatar Phoomparin Mano avatar Andy Nicholson avatar Yuki Tanaka avatar Daniel avatar Nik Holo avatar Eli avatar Dimitrij Klesev avatar Valerii Baleiko avatar Ryan Scott Lewis avatar Christian Bagley avatar Uscreen Bot avatar Yılmaz Demir avatar Moose avatar Will Lewis avatar Igor Tarasenko avatar Buğra Ekuklu avatar Sergey Kuznetsov avatar Ivan Kuzmenko avatar  avatar Pim Snel avatar Anthony Scalisi avatar Josh avatar Byungjik Roh avatar elvuel avatar Matan Silver avatar Montana Flynn avatar Xiaohan Song avatar Geofrey Ernest avatar WolfLee avatar James Aspinwall avatar Nigel Sheridan-Smith avatar Kent Gruber avatar Eduardo Stuart avatar George Plymale II avatar ylluminate avatar Eliuk Blau avatar Aaron Godin avatar Matt Petty avatar  avatar Richard Fairhurst avatar lajunta avatar osfx avatar jasdeep singh avatar 韦昭 avatar Omar Bahareth avatar sablib avatar xcplus avatar Armando Magalhães avatar Kingsley Lewis avatar Casey Strouse avatar  avatar Ricardo Tomasi avatar Taiyo Mizuhashi avatar  avatar Romain Franceschini avatar Sean Johnson avatar 엘련(Jisu Kim) avatar Xavier Bick avatar George Opritescu avatar Patrick Armitage avatar Ivan avatar Xavier Lucas avatar Leonard Schütz avatar Gabriel Rios avatar Zura Guerra avatar Kyle Ashmore avatar Luke Butler avatar Jeremy Bae avatar Ivan Palamarchuk avatar Ernest avatar Chris Slott avatar Dumitru Railean avatar Jeremy Woertink avatar Mike Koepke avatar

Watchers

Stig Kleppe-Jørgensen avatar evandrix avatar James Cloos avatar  avatar Roberto Salas avatar  avatar Nob avatar Ivan avatar Iain Moncrief avatar

hoop's Issues

Create Documentation

Kind of a feature/enhancement kind of issue:

Make a documentation for this somewhere, like GitBook.

Doesn't run in Crystal 0.20.0

Error while trying to run an example (all examples fail):

$ crystal run example/ns_log_test.cr
Error in example/ns_log_test.cr:1: while requiring "./../src/hoop"

require "./../src/hoop"
^

in src/hoop.cr:2: while requiring "./foundation/*"

require "./foundation/*"
^

in src/foundation/calayer.cr:1: while requiring "./nsobject"

require "./nsobject"
^

in src/foundation/nsobject.cr:306: expanding macro

    objc_method "retain"
    ^

in macro 'objc_method' /Users/aemadrid/code/aem/crystal/hoop/src/foundation/nsobject.cr:185, line 2:

   1.
>  2.         objc_method_helper(self.to_objc, "retain", nil, nil, nil)
   3.
   4.

expanding macro
in src/foundation/nsobject.cr:40: can't execute OpAssign in a macro

      {{ "##{crystal_method ||= method_name}".id }}
             ^


aemadrid at cortazar in ~/code/aem/crystal/hoop (master●●)
$ crystal -v
Crystal 0.20.0 (2016-11-22)```

example in readme doesn't work

the require line doesn't work as-is and once you eventually coax it into something that does work you get an app that just spits out

2018-06-09 20:11:53.365 crystal-run-app.tmp[15858:15753157] app launched

and nothing else. Judging by the code there's supposed to be a window and a button and the button should do something when clicked.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.